/*** File class: Create, delete, rename, get path, create time, etc., is the only action class related to the file itself*/ Public classMain { Public Static voidMain (string[] args) {//File.separator represents a delimiterFile F1 =NewFile ("C:" + file.separator + "fuck" + file.separator + "JavaTest1.txt"); String S1= File.pathseparator;//Path delimiterSystem.out.println (File.separator + "" +S1); BooleanB1 = F1.exists ();//whether the file existsSystem.out.println (B1); if(!B1) { Try { BooleanBT1 = F1.createnewfile ();//Create a fileSystem.out.println (BT1); } Catch(IOException e) {e.printstacktrace (); }} System.out.println (F1.delete ()); //Deleting Files//System.out.println (""); Shortcut: Hit Sout, then press the TAB keySystem.out.println (F1.getparent ());//get the top-level path to the fileSystem.out.println (F1.isdirectory ());//determine if it is a directoryFile F2=NewFile ("C:" + file.separator + "fuck" +file.separator); String[] fname= F2.list ();//List all file names in a folder for(String i:fname) System.out.println (i); file[] Files= F2.listfiles ();//lists all the files in the file, returned as an array of files for(File i:files) System.out.println (I.getname () + "" +i.length ()); File f3=NewFile ("C:\\fuck\\javatest1"); System.out.println (F3.mkdir ()); //Create a folderF3.delete (); System.out.println (F3.renameto (NewFile ("C:\\fuck\\javatest2"));// Renaming }}
Java note 11__file class/file class jobs