The file class is the only class in the IO package that represents the information for the disk file itself, not the contents of the files
The file class defines some platform-independent methods to manipulate files,
Directories in Java are used as a special type of file, and the list method can return all subdirectories and filenames in the directory
The path delimiter under UNIX is (/), the path delimiter under DOS is (\), and Java can correctly handle both path separators
Demo
Determines whether a file exists, is deleted, does not exist, and creates
Code Snippets
File F = new file ("1.txt");
if (f.exists ()) {
F.delete ();
}else{
F.createnewfile ();
}
System.out.println ("File name" +f.getname ()); Get the file name
System.out.println ("File path" +f.getpath ()); Get file relative path (path includes file name)
System.out.println ("File ASB Path" +f.getabsolutepath ()); Get the file absolute path
System.out.println (F.exists ()? " Exists ":" Not Exists "); Determine if a file exists
System.out.println (F.canread ()? " Read ":" not read "); Determine if a file is readable
System.out.println (F.isdirectory ()? " Directory ":" Not being directory "); Determine if a file is a directory
System.out.println ("Filed last Modifield Time" +f.lastmodifield ());//File Latest modified
System.out.println ("File name" +f.getname ()); Get the file name
Review the file class of Javaio