Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2007

Tip: Looking for answers? Try searching our database.

size (i.e. length) of an OS file: gotten from the OS ?

Thread view: 
Sébastien de Mapias - 08 Nov 2007 20:17 GMT
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



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.