获取Android SDK中的文件的大小? [英] Get the file size in android sdk?
问题描述
我是一个非常ST * PID的人,我有一个问题得到一个文件的大小。我有以下的code:
i am a very st*pid person and i have a problem getting the size of a file. I have the following code:
File file = new File("/sdcard/lala.txt");
long length = file.length();
和总长度为零,是零。 我使用的Android SDK(不知道是什么版本)时,code是一种活性内运行,我创建了一个SD卡,嗯,我不知道还能说些什么,或许这是一个权限问题。 有什么我失踪? 要求提供更多信息,如果您需要这样。 先谢谢了。
And always length is zero, yes zero. I am using Android SDK (not sure what version), the code is running inside an Activity, i have created a sdcard, mmm, i don't know what else to say, probably it is a permission issue. Is there anything i am missing ?? Ask for more info if you need so. Thanks in advance.
推荐答案
在 File.length()
方法返回以下根据javadoc的:
The File.length()
method returns the following according to the javadoc:
的长度,以字节为单位,表示此抽象路径名,或如果文件不存在0L文件。某些操作系统可能返回0L的路径名表示系统相关的实体,如设备或管道。 的
正如你所看到的,零可退换:
As you can see, zero can be returned:
- 如果该文件存在,但包含零字节。
- 如果该文件不存在,或者
- 如果该文件是一些特定于操作系统的特殊文件。
我的钱是在第二个案例;即你打错文件名/路径。尝试调用 File.exists()
的文件名,看看有什么,告诉你。在另外两起案件也是可能的,我想。
My money is on the second case; i.e. that you have the wrong filename / pathname. Try calling File.exists()
on the filename to see what that tells you. The other two cases are possible too, I guess.
(根据记录,最 / proc中/...
文件还具有零一个明显的文件大小。而Android是基于Linux的。 )
(For the record, most /proc/...
files on a Linux-based system also have an apparent file size of zero. And Android is Linux based.)
这篇关于获取Android SDK中的文件的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!