Write a java program to enter a filename, your program must check whether the file exists or not, if it exists then display the properties of that file.
class12 th english medium
Answers
Answered by
1
Answer:
import java.io.*;
import java.util.*;
class fileExists
{
public static void main(String[] args)
{
System.out.print("Enter the name of the file:");
Scanner sc = new Scanner(System.in);
String fname = sc.nextLine();
File myObj = new File(fname);
if (myObj.exists())
{
System.out.println("File name: " + myObj.getName());
System.out.println("Absolute path: " + myObj.getAbsolutePath());
System.out.println("Writeable: " + myObj.canWrite());
System.out.println("Readable " + myObj.canRead());
System.out.println("File size in bytes " + myObj.length());
}
else
{
System.out.println("The file does not exist");
}
}
}
Explanation:
Similar questions