/home/caleb/ASDV-Java/Semester 2/Assignments/lab6-Exceptions_CalebFontenot/src/main/java/com/mycompany/lab6/exceptions_calebfontenot/TestFileClass.java |
package com.mycompany.lab6.exceptions_calebfontenot;
import java.util.Scanner;
@author
public class TestFileClass {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter a file path or directory: ");
String filePath = input.nextLine();
testFile(filePath);
}
public static void testFile(String filePath) {
java.io.File file = new java.io.File(filePath);
System.out.println("Does it exist? " + file.exists());
System.out.println("The file has " + file.length() + " bytes.");
System.out.println("Can it be read? " + file.canRead());
System.out.println("Can it be written? " + file.canWrite());
System.out.println("Is it a directory? " + file.isDirectory());
System.out.println("Is it a file? " + file.isFile());
System.out.println("Is it absolute? " + file.isAbsolute());
System.out.println("Is it hidden? " + file.isHidden());
System.out.println("The absolute path to this file is " + file.getAbsolutePath());
System.out.println("Last modified on " + new java.util.Date(file.lastModified()));
}
}