• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

File length

 
Abder-Rahman Ali
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The length in bytes

Thats what the API says ...
http://java.sun.com/javase/6/docs/api/java/io/File.html#length()
 
Abder-Rahman Ali
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic