Question: / / Program describes two files / / prompts user to see file statistics / / tells which one is newer and which one is

// Program describes two files
// prompts user to see file statistics
// tells which one is newer and which one is larger
// Note - change path for data files if necessary on your computer
import java.nio.file.*;
import java.nio.file.attribute.*;
import java.io.IOException;
import java.util.*;
public class DebugEleven1
{
public static void main(String[] args)
{
Scanner kb = new Scanner(System.in);
String choice;
Path file1=
Paths.get("/home/nt-user/workspace/DebugData1.txt");
Path file2=
Paths.get("/home/nt-user/workspace/DebugData2.txt");
try
{
BasicFileAttributes attr1=
Files.readAttributes(file1, BasicFileAttributes.class);
System.out.println("Do you want to see statistics for first file?");
System.out.print("Y or N >>");
choice = kb.nextLine();
if(choice.equals("Y"))
{
System.out.println("File: "+ file1.getFileName());
System.out.println("Creation time "+ attr1.creationTime());
System.out.println("Last modified time "+ attr1.lastModifiedTime());
System.out.println("Size "+ attr1.size());
}
BasicFileAttributes attr2=
Files.readAttributes(file2, BasicFileAttributes.class);
System.out.println("Do you want to see statistics for second file?");
System.out.print("Y or N >>");
choice = kb.nextLine();
if(choice.equals("Y"))
{
System.out.println("
File: "+ file2.getFileName());
System.out.println("Creation time "+ attr2.creationTime());
System.out.println("Last modified time "+ attr2.lastModifiedTime());
System.out.println("Size "+ attr2.size());
}
if(attr1.creationTime().compareTo(attr2.creationTime())>0);
System.out.println("
"+ file1.getFileName()+
" was created earlier");
else
System.out.println("
"+ file1.getFileName()+
" was not created earlier");
if(attr1.size()> attr2.size())
System.out.println(file1.getFileName()+" is larger ");
else
System.out.println(file1.getFileName()+" is not larger");
}
catch(IOException e)
{
System.out.println("IO Exception");
}
}
}

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 Databases Questions!