This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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: 19541
    
  16

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: File length
 
Similar Threads
Urgent-printing the data onto the printer problem?
Inteface return type
Static Methods Don't Work
Data File Format and reading header information
Listing files in directory (and subdirectory)