Mind Mapping
Code actual Demo
1 PackageCom.hanqi.io;2 3 ImportJava.io.*;4 5 Public classTest1 {6 7 Public Static voidMain (string[] args) {8 //file Files9 Ten //Construction Method (file full path + file name) OneFile File =NewFile ("D:\\test1.txt"); A - //determine if a file exists - if(File.exists ()) the { -System.out.println ("File exists"); - -System.out.println ("GetAbsolutePath =" +File.getabsolutepath ()); + -System.out.println ("getParent =" +file.getparent ()); + ASystem.out.println ("GetName =" +file.getname ()); at - //Deleting Files - //File.delete (); - - //Renaming a file -File.renameto (NewFile ("D:/test2.txt")); in - to } + Else - { the *SYSTEM.OUT.PRINTLN ("File does not exist"); $ Panax Notoginseng //Create a new file - //Controllable Exception the Try + { A the file.createnewfile (); + -System.out.println ("File creation succeeded"); $ $ } - Catch(IOException e) - { the -System.out.println ("File creation failed");Wuyi the e.printstacktrace (); - } Wu } - About $ - } - -}
Create a file
PackageCom.hanqi.io;ImportJava.io.*; Public classText2 { Public Static voidMain (string[] args) {//Operating DirectoryFile dir =NewFile ("D:/test/test"); if(!dir.exists ()) { //Create a directory if(Dir.mkdirs ()) {System.out.println ("Create directory Success"); } Else{System.out.println ("Failed to create directory"); }} File File=NewFile ("D:/test/test.txt");//specify a specific file if(File.exists ()) {}Else { Try{file.createnewfile (); System.out.println ("Create file succeeded"); } Catch(IOException e) {e.printstacktrace (); System.out.println ("Failed to create directory"); } } }}
Learn to summarize Java input and output streams