Write a program that displays the file's name, parent, size, time of last modification

Write a program that displays the file's name, parent, size, time of last modification and write another program that determines whether the two files are located in the same folder?
LVL 1
Draph_89Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Draph_89Author Commented:
import java.io.*;

public class FileStatistics
{
      public static void main(String[] args) throws IOException
      {
            // create file object
            File myFile = new File("myDocument.txt");

            //display file information
            System.out.println("\nThe file \"myDocument.txt\" has the following properties:");
            System.out.println("_________________________________________________________");
            System.out.println("\tFile Name: \t" + myFile.getName());
            System.out.println("\tParent Dir.: \t" + myFile.getParent());
            System.out.println("\tFile Size: \t" + myFile.length());
            System.out.println("\tLast Modified: \t" + myFile.lastModified());
      }
}



//create directory objects
  File file1Dir = new File(".");
  File file2Dir = new File(".\\Test");
 
  // create file objects
  File file1 = new File(file1Dir, "myDoc1.txt");
  File file2 = new File(file2Dir, "myDoc2.txt");

Thanks for the help. It there a better way of writting this program. The program works but I looking for better way. Can you provide assistance.
Learn SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

Draph_89Author Commented:
I am looking for a better way to make this look and work better. The code is generic and I would like to know if I can get someone to help. Thanks.
boonlengCommented:
Can you provide more information on what you are trying to achieve?
You want to make it as a utility class, or more organise, or something else?
suprapto45Commented:
Hi,

Please have a look at
http://www.rgagnon.com/bigindex.html

and under File heading. You will find lots of good information.

>>"determines whether the two files are located in the same folder"
First, you need to check whether both of the files are exist
http://www.rgagnon.com/javadetails/java-0070.html

and if they both exists, make sure that their current paths are the same
http://www.rgagnon.com/javadetails/java-0076.html

Regards
Dave

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Draph_89Author Commented:
Thanks Dave, for the information.
suprapto45Commented:
Glad I could help.

Regards
Dave
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.