"Java-io" Java file operation

Source: Internet
Author: User

File

File can create new, delete, rename files and directories, but cannot view file contents.

Construction method
public File(string pathName);//以path路径创建对象
publicFile(StringString child);//以parent为父路径,child为子路径创建File对象

Unix under Path delimiter is '/', Windows is ' \ ' or '/'

A program that understands the file class
//create path plus file in D driveFile d1= New File ("D:/dir1");//Create D1 path            if(!d1.exists()) {D1.mkdir ();//If the D1 path does not exist, create the path} file D2 = new file (d1,"D2");//Create D2 path            if(!D2.exists()) {d2.mkdirs (); Creates a path based on the D1 path to the parent path if the D2 path does not exist} Filefile= new File (D2,"Text.txt");//Create a new file with the files object            if(!file.exists()) {try {file. CreateNewFile ();//Create file}Catch(IOException e) {//TODO auto-generated catch blockE.printstacktrace (); }            }

"Java-io" Java file operation

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.