Hi,
I'd like to know how Java knows the size of a file.
When you simply do
File f = new File("/usr/tmp/stuff.txt");
long si = f.length();
it performs a call to its own reference of FileSystem.getLength
on itself, and when I check the getFileSystem() method in the
FileSystem class I see it's native...
So I guess the size (amongst other properties) is a data that
f receives when it's instantiated - or I'm mistaken ?
Thanks.
Seb
Daniel Pitts - 08 Nov 2007 21:07 GMT
> Hi,
> I'd like to know how Java knows the size of a file.
[quoted text clipped - 11 lines]
> Thanks.
> Seb
It probably isn't when its instantiated, but rather when that method is
invoked... A File object doesn't actually represent a file, but a
file-location. Therefor, the file itself can change over time.
Being that it is a native call, I'm guessing that it is translated to a
call to the OS.

Signature
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
Roedy Green - 09 Nov 2007 00:13 GMT
On 8 Nov 2007 12:17:59 -0800, Sébastien de Mapias
<sglrigaud@gmail.com> wrote, quoted or indirectly quoted someone who
said :
>So I guess the size (amongst other properties) is a data that
>f receives when it's instantiated - or I'm mistaken ?
nope. The implementation is:
return fs.getLength(this);
where fs is the file system. It does not call getLength until you
call File.length()
the length can change over time.

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com