Meaningless Drivel is fun!*
The moose likes I/O and Streams and the fly likes File length Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "File length" Watch "File length" New topic
Author

File length

Abder-Rahman Ali
Ranch Hand

Joined: May 22, 2008
Posts: 138
If I do the following for example:



What does the number returned by fLength represent? In other words, what is it counting in the file? If I have an image, what is it counting here for example?

Thanks.
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
The length in bytes

Thats what the API says ...
http://java.sun.com/javase/6/docs/api/java/io/File.html#length()


JDBCSupport - An easy to use, light-weight JDBC framework -
Abder-Rahman Ali
Ranch Hand

Joined: May 22, 2008
Posts: 138
Sebastian Janisch wrote:The length in bytes

Thats what the API says ...
http://java.sun.com/javase/6/docs/api/java/io/File.html#length()


Thanks Sebastian.

So, is it counting the bytes in a file then?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19654
    
  18

Depends on what you see as "counting". Does it go through the entire file and count bytes that way? No. Does it ask the file system what the file size is? Yes.

Keep in mind that the length() is returned as a long for a reason. An int can go up to 2^31 - 1 which is one byte shy of 2GB. If your file is larger the cast will give you strange results.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
 
subject: File length
 
Similar Threads
Data File Format and reading header information
Urgent-printing the data onto the printer problem?
Listing files in directory (and subdirectory)
Inteface return type
Static Methods Don't Work