🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.api
Article #62

Re: File.lengh() return 0 while the file's length > 0 on Linux

#62
From: Kevin Dean [TeamB]
Date: Thu, 17 Mar 2005 16:28
39 lines
2297 bytes
Chris wrote:

> When using File.length to get the size of a file on linux, it returns
> 0; but I am sure the file has contents, Could someone give me a hint?
> 
> Thanks in advance .
> 
> //test.java
> import java.io.*;
> public class test
> {
>        public static void main(String args[])
>        {
>                File file = new File("/proc/mdstat");
>                System.out.println("file.length(): " + file.length());
>        }
> }

The /proc filesystem is a special file system that maintains process
state.  The contents don't exist on disk but rather in memory, and the
contents are highly dynamic.  Because you're not opening a real file
per se, there's no easy way to determine the length, so Java returns 0.

Details on /proc can be found here:

http://www.freeos.com/articles/2879/

-- 
Kevin Dean [TeamB]
Dolphin Data Development Ltd.
http://www.datadevelopment.com/

NEW WHITEPAPERS
Team Development with JBuilder and Borland Enterprise Server
Securing Borland Enterprise Server
http://www.datadevelopment.com/papers/index.html

Please see Borland's newsgroup guidelines at
http://info.borland.com/newsgroups/guide.html
Technical Details
Message-ID: <xn0dzuxe9bpec8000-kdean@www.teamb.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!newshub.sdsu.edu!tethys.csu.net!arclight.uoregon.edu!hammer.uoregon.edu!enews.sgi.com!news.xtra.co.nz!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <42392992@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 1089d0,de041f602cc051c9
X-Google-Attributes: gid1089d0,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Kevin Dean [TeamB]" <NkOdSePaAnM@datadevelopment.com>
Subject: Re: File.lengh() return 0 while the file's length > 0 on Linux
Newsgroups: borland.public.jbuilder.java.api
References: <42392992@newsgroups.borland.com>
Organization: Dolphin Data Development Ltd.
User-Agent: XanaNews/1.17.2.7
X-Face: ":yn4zt^A_dn>6~{YJmu^B\'4w)e:apPM\VC=Dvf&*tASxX9|BYczkFd$xr.$vNSZ[3Uobr
 p]c4\+\l){!WQI.$]veP({HLd;CDYH?iN
Message-ID: <xn0dzuxe9bpec8000-kdean@www.teamb.com>
X-Ref: newsgroups.borland.com ~XNS:00000122
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-2022-jp
NNTP-Posting-Host: 24.57.153.235
Date: 17 Mar 2005 08:28:34 -0800
X-Trace: newsgroups.borland.com 1111076914 24.57.153.235 (17 Mar 2005 08:28:34 -0800)
Lines: 39
X-Authenticated-User: kdean
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!newshub.sdsu.edu!tethys.csu.net!arclight.uoregon.edu!hammer.uoregon.edu!enews.sgi.com!news.xtra.co.nz!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail