Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Java Basics
|
Java Basics General beginning Java language questions that don't fit in one of the more specific forums. Please specify what version.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 2nd, 2006, 06:37 AM
Authorized User
 
Join Date: Jan 2005
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default Display file Access and Created date

Hi,

i was wondering if someone could help me. i want to be able to print some properties of a file i.e. the date it was created and accessed. can anyone help me. i have tried looking for the methods but can't find them.

thanks in advanced

scoobie

here is the code i'm using. this code returns a list of files and their sizes in a particular directory:

Code:
DirectoryDialog dialog = new DirectoryDialog(shell);
dialog.setText("Browse For Folder");
dialog.setFilterPath("c:\\"); // Windows specific

File dir = new File("directoryName");
File files[] = dir.listFiles();
String res = dialog.open();

File path = new File(res);
files = path.listFiles();
System.out.println("PATH is: " + path + "\n\n");

int i;
int count = 1;
for(i = 0; i < files.length; i++)
{
File filename = files[i];
long size = filename.length()/1000;
//Date modify = files[i].lastModified();
System.out.println(count + "  Filename: " + filename + "\n" + "Size:  " + size + " KB\n" + "Path:  " + path + "\n\n");
}
i++;

 
Old March 16th, 2007, 06:53 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 373
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi,

To know the size of the file you can not use File class, for that you have to open a FileInputStream to the file and call the inputstream.available() method to get the no.of bytes available in the file [i.e. file size in bytes], and to know the last modified date you can use File class and call the lastModified() method, which will return date in long data type, you can pass it to Date class constructor and create a Date class object and you can use SimpleDateFormat class of java.text package to conver the date formate to what ever format you want.

Regards,


- Rakesh





Similar Threads
Thread Thread Starter Forum Replies Last Post
Why Created 2 Excel file? cyclone9 SQL Server 2000 0 September 8th, 2008 04:20 AM
Open Excel to display created forms Borhani Excel VBA 2 January 19th, 2008 07:42 AM
Empty rows created in Access table ayazhoda Access VBA 7 May 10th, 2007 06:23 AM
How to display a access webpage on current date kenbeyond Access VBA 2 October 13th, 2005 06:42 AM
Excel Workbook created from Access VBA clueless_may Access VBA 0 June 8th, 2004 09:42 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.