Java learning notes-basic methods of the File class, java learning notes-file
Gradually develop the habit of writing blogs -----"
Some time ago, I/O stream in the java of Mars was not fully understood, and it was difficult to find the I/O Stream. Today, I read other teaching courses, books, and notes to record my daily study and life.
File class methods:
1 package com. cnblogs; 2 3 import java. io. file; 4 import java. io. IOException; 5 6 public class FileTest {7 public static void main (String [] args) throws IOException {8 File file File = new File ("F:" + File. separator + "temp" + File. separator + "a.txt"); 9 // determine whether the directory is 10 System. out. println (file. isDirectory (); 11 // determine whether the file is 12 System. out. println (file. isFile (); 13 // create a new file 14 file. createNewFile (); 15 System. out. println (file. isFile (); 16 System. out. println (file. isDirectory (); 17 // determines whether the System is readable. out. println (file. canRead (); 19 // judge whether the System can be written 20. out. println (file. canWrite (); 21 // get the length 22 System. out. println (file. length (); 23 // obtain the path strength 24 System. out. println (file. getPath (); 25 // get the file parent directory 26 System. out. println (file. getParentFile (); 27 // get the separator 28 System. out. println (file. pathSeparator); 29 System. out. println (file. separator); 30} 31 public static void main2 (String [] args) throws IOException {32 File file = new File ("F:" + File. separator + "temp" + File. separator + "a.txt"); 33 // judge whether the file exists 34 if (file. exists () {35 file. renameTo (new File ("F:" + File. separator + "temp" + File. separator + "B .txt"); 36} 37 // if the above does not exist, create a new file 38 else {39 file. createNewFile (); 40} 41 42} 43}