//Program to read a file and display its properties
import java.io.*;
import java.util.*;
import javax.swing.*;
class Fileproperties
{
public static void main(String args[])throws IOException
{
Scanner scr=new Scanner(System.in);
System.out.print(“nEnter any file name: “);
String str=scr.nextLine();
File f=new File(str);
JFileChooser c=new JFileChooser();
if(f.exists())
{
System.out.println(f.canRead()?”File is Readable”:”File is not Readable”);
System.out.println(f.canWrite()?”File is Writable”:”File is not Writaable”);
System.out.println(“Length of the file is : “+f.length());
System.out.println(“nType of the file is: “+c.getTypeDescription(f));
}
else
System.out.println(“File does not exists”);
}
}
Output:
Enter any file name: Fileproperties.java
File is Readable
File is Writable
Length of the file is : 778
Type of the file is: JAVA File