Package Com.yeqc.testdemo;import Java.io.file;public class Readfileproperty {public static void main (string[] args) { File File = new file ("Text.txt");//Determine if the document exists SYSTEM.OUT.PRINTLN ("Determine if the file exists" +file.exists ());//Read file name System.out.println ("Read file name" +file.getname ());//Read file path System.out.println ("Read file path" +file.getpath ());//Read File absolute path System.out.println (" Reads the file absolute path "+file.getabsolutepath ()"),//reads the file parent path System.out.println ("Read file parent path" +new file (File.getabsolutepath ()). GetParent ());//Read File size System.out.println ("Read File size" + (float) file.length ()/1000+ "KB");//Determine if the file is hidden System.out.println ("Determine if the file is hidden" +file.ishidden ());//Determine if the file is readable System.out.println ("Determine if the file is readable" +file.canread ()); Determine if the file can be written System.out.println ("Determine if the file is writable" +file.canwrite ());//Determine if the file is a folder System.out.println ("Determine if the file is a folder" + File.isdirectory ());}}
Operation Result:
Determine if the file exists true read file name text.txt read file path text.txt read file absolute path C:\Users\Administrator\workspace01\ReadFileProperty\ Text.txt Read File parent path C:\Users\Administrator\workspace01\ Readfileproperty Read File size 0.013KB Determine whether the file is hidden false to determine whether the file is readable true to determine if the file is writable true to determine if the file is a folder false
Java Local file Operations (iii) Read of file properties