Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Output File Properties  RSS feed

 
K Terr
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I was wondering if someone could help me. I am trying to output a list of files and properties to the screen. I have a file browser popping up and when i select a directory and click ok it outputs the path and list of files in that directory. However, i also want to output the size, type and created time of each file in that directory. i have an array that holds all the files but i am having trouble doing this. can anyone please help me.

Thanks in advanced,

K

here is the code i am using:


[ August 01, 2006: Message edited by: K Terr ]
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
filename.length() is, not surprisingly, the length of the file's name. Dividing by 1000 gives zero because, in general, the length of a filename is far less than 1000!

The java.io.File class has a length() method too, which does indeed give you the size of a file in bytes. Instead of using list() to get a list of filenames, use listFiles() to get a list of File objects; then query these objects for the name, size, etc.
 
K Terr
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

thanks for replying, i got it to print the size of the file. i still cant get it to print the date the file was created or accessed. i can't seem to find the methods. can you help me again

K
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 15861
81
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a good look at the API documentation of class java.io.File.
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by K Terr:
Hi,

thanks for replying, i got it to print the size of the file. i still cant get it to print the date the file was created or accessed. i can't seem to find the methods. can you help me again

K


There are no such methods. Pure Java can only get you the last-modified date/time.

If you really need the creation date/time and the last-accessed date/time, you must use native code (JNI).
 
K Terr
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Peter,

Do you know any good tutorials that i could use to get this to work?

thanks
k
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!