Write a Java Program that reads a file name from the user, then display information about whether the file exists, whether the file is readable, whether the file is writable, the type of file and the length of the file in bytes.
Program Code:
import java.io.*;
class FileEx
{
public static void main(String[] args)
{
DataInputStream dis=new DataInputStream(System.in);
File f=new File("D:/Lab/abc/abc.txt");
System.out.println("File Name = "+f.getName());
System.out.println("File Path = " +f.getPath());
System.out.println("File parent = "+f.getParent());
System.out.println(f.isFile()?" is a File":"not a file");
System.out.println(f.isDirectory()?"it is a directory":"not a directory");
System.out.println(f.canRead()?" it is readable":"it is not readable");
System.out.println(f.canWrite()?"it is writable":"it is not writable");
System.out.println("length of file is"+f.length());
}
}
Post A Comment:
0 comments: