Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

/ / 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Murach's SQL Server 2012 For Developers

Authors: Bryan Syverson, Joel Murach, Mike Murach

1st Edition

1890774693, 9781890774691

More Books

Students also viewed these Databases questions

Question

d. In what sports does the person consult?

Answered: 1 week ago

Question

Understand developments in knowledge creation and management

Answered: 1 week ago

Question

Explain key ideas of workplace learning

Answered: 1 week ago

Question

Explain how HRD may be implemented

Answered: 1 week ago