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