Discussion:
File.lengh() return 0 while the file's length > 0 on Linux
(too old to reply)
Chris
2005-03-17 07:02:15 UTC
Permalink
Howdy,

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());
}
}
Kevin Dean [TeamB]
2005-03-17 16:28:34 UTC
Permalink
Post by Chris
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
Loading...