Topic: 在linux上,用File.length() 获取有些文件的长度是0,请问这是怎么回事?

  Print this page

1.在linux上,用File.length() 获取有些文件的长度是0,请问这是怎么回事? Copy to clipboard
Posted by: zerol
Posted on: 2005-03-17 14:46

我在linux上,用File.length() 获取有些文件的长度是0, 请问这是怎么回事?
TIA

//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());
}
}

2.Re:在linux上,用File.length() 获取有些文件的长度是0,请问这是怎么回事? [Re: zerol] Copy to clipboard
Posted by: wtfg_N188
Posted on: 2005-03-18 16:03

不会吧?要不就是你的文件长度确实为0。
还有,提醒你一问题,在这里要注意加上try{}catch(){}语句哈~~~~~~

3.Re:在linux上,用File.length() 获取有些文件的长度是0,请问这是怎么回事? [Re: zerol] Copy to clipboard
Posted by: floater
Posted on: 2005-03-18 22:55

is this soft link?

4.Re:在linux上,用File.length() 获取有些文件的长度是0,请问这是怎么回事? [Re: zerol] Copy to clipboard
Posted by: zerol
Posted on: 2005-03-19 01:36

Here is the answer from TeamB:

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/


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923