Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Java and JDK > Java Basics
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 2nd, 2006, 06:37 AM
Authorized User
Join Date: Jan 2005
Location: , , .
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default Display file Access and Created date


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


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

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");

Reply With Quote
  #2 (permalink)  
Old March 16th, 2007, 06:53 AM
Friend of Wrox
Join Date: Mar 2007
Location: Hyderabad, A.P., India.
Posts: 373
Thanks: 0
Thanked 1 Time in 1 Post


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.


- Rakesh
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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

All times are GMT -4. The time now is 07:57 PM.

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