Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

File length  RSS feed

 
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
Posts: 21048
85
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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!