Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In Java Create a file using any word processing program or text editor. Write an

ID: 3630032 • Letter: I

Question

In Java
Create a file using any word processing program or text editor.

Write an application that displays the file's name, containing

folder size and time of last modification.
Save as FileStatistics
This is what I have with errors, what am I missing here ?
Thanks
<CODE>
import java.nio.file.*;
import java.nio.file.attribute.*;
import java.nio.file.attribute.Attributes;
import java.io.IOException;


public class FileStatistics
{
public static void main(String[] args)
{
Path filePath =
Paths.get("C:\Java\FileStatistics.txt");
try
{
BasicFileAttributes attr =
Attributes.readBasicFileAttributes(filePath);
System.out.println("Creation time " + attr.creationTime());
System.out.println("Last modified time " + attr.lastModifiedTime());
System.out.println("Size " + attr.size());
}
catch(IOException e)
{
System.out.println("IO Exception");
}
}
}
<CODE>

Explanation / Answer


import java.nio.file.*;
import java.nio.file.attribute.*;

public class FileStatistics {

    public static void main(String[] args) {

        try {
            Path filePath = Paths.get("C:\Java\FileStatistics.txt");
            BasicFileAttributes attr = Files.readAttributes(filePath, BasicFileAttributes.class);
            System.out.println("Creation time " + attr.creationTime());
            System.out.println("Last modified time " + attr.lastModifiedTime());
            System.out.println("Size " + attr.size());
        } catch (Exception e) {
            System.out.println(e.toStringg());
        }
    }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote