<!--new, traverse, change--
public classIndex { public Static voidmain (string[] Args) {index (); Test (); FilePath (); } Private Static voidFilePath () {//creates a file class relative path that defaults to the current projectFile File =NewFile ("src"); //get the path to all files (directories) in the current directoryfile[] files =File.listfiles (); for(File f:files) {System.out.println (f); } } Private Static voidTest () {//creates a file class relative path that defaults to the current projectFile File =NewFile ("src/file operation/456/789/123"); //Create folder (directory)System.out.println (file.mkdirs ()); } Private Static voidindex () {//creates a file class relative path that defaults to the current projectFile File =NewFile ("src/file operation/123.txt"); //determine the authenticity of a file (whether it exists) BooleanIsfile =File.isfile (); //if it does not exist, create the current file if(!Isfile) { Try { //Create a fileFile.createnewfile (); } Catch(ioexception e) {System.out.println ("file Creation failed"); } } Else { //file renameFile.renameto (NewFile ("src/file operation/123.chm")); } }}
<!--file filtering--
public classIndex { public Static voidmain (string[] Args) {File dir=NewFile ("src/new _ traverse _ change"); //get all the files (directories) under the directory and filter them,file[] fs = Dir.listfiles (Newfilenamefilter () {//implementation of filtering methods in the filter interface public BooleanAccept (File dir, String Name) {return NewFile (dir, name). isfile () && name.endswith ("txt"); } }); for(File F:fs) {System.out.println (f); } }}
JAVA IO (file new, traverse, change, filter)