Question: Create a file using any word - processing program or text editor. Write an application called FileStatistics that prompts the user for the filename and

Create a file using any word-processing program or text editor. Write an application called FileStatistics that prompts the user for the filename and displays the files path, name, folder, size, and time of last modification.
The default file path for your project directory is ./.
An example of the program is shown below:
Enter file name >> example.txt Path is ./example.txt File name is example.txt Folder name is workspace File's size is 447 File's creation time is 2021-10-18T17:26:21.224324Z
Task 01: Create the FileStatistics class.
Task 02: The FileStatistics class displays the correct statistics on the provided file.
import java.nio.file.*;
import java.nio.file.attribute.*;
import java.io.IOException;
public class FileStatistics
{
public static void main(String[] args)
{
Path filePath = Paths.get("FileStatistics_file.txt");
try
{
BasicFileAttributes attr = Files.readAttributes(filePath, BasicFileAttributes.class);
System.out.println("");
System.out.println("File Information");
System.out.println("");
System.out.println("Name: "+ filePath.getFileName().toString());
System.out.println("Size: "+ attr.size()+" bytes");
System.out.println("Last Modified: "+ attr.lastModifiedTime());
System.out.println("");
}
catch (IOException error)
{
System.out.println("IO Exception: "+ error.getMessage());
}
}
}
This is what I have - Task 1 works but I cant figure out Task 2

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!