In Java IO, the file class must be mastered. Its common API usage is shown in the example.
PackageCom.westward.io;ImportJava.io.File;Importjava.io.IOException; Public classFiledemo { Public Static voidMain (string[] args) {File file=NewFile ("D:\\javaio"); @SuppressWarnings ("Static-access") File file2=NewFile ("D:" + file.separator+ "Javaio\\imooc.txt"); File File3=NewFile ("D:\\javaio\\txt\\read"); System.out.println (File3.exists ()); if(!file3.exists ()) {File3.mkdirs (); } System.out.println (File3.exists ()); System.out.println (file2); System.out.println (File2.getabsolutepath ()); System.out.println (File2.getname ()); System.out.println (File2.getparentfile ()); System.out.println (File2.getparentfile (). GetAbsolutePath ()); if(File.exists ()) {file.delete (); } System.out.println (File2.isdirectory ()); System.out.println (File2.isfile ()); if(!file2.exists ()) { Try{file2.createnewfile (); } Catch(IOException e) {//TODO auto-generated Catch blockE.printstacktrace (); } } }}
Common operations for the file class of the IO of Java