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());
}
}
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: