Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/203.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 查询有关文件的信息_Android_File_Cursor - Fatal编程技术网

Android 查询有关文件的信息

Android 查询有关文件的信息,android,file,cursor,Android,File,Cursor,对于content:URI,我使用ContentProvider/Contentresolver检索有关修改日期、大小和数据的信息。我希望对file:URI执行相同的操作,但在尝试以下代码时: CursorLoader loader = new CursorLoader(this, uri, proj, null, null, null); Cursor cursor = loader.loadInBackground(); 游标返回为null。如何获得添加/修改的文件大小、数据和日期?我可能

对于content:URI,我使用ContentProvider/Contentresolver检索有关修改日期、大小和数据的信息。我希望对file:URI执行相同的操作,但在尝试以下代码时:

CursorLoader loader = new CursorLoader(this, uri, proj, null, null, null);
Cursor cursor = loader.loadInBackground();

游标返回为null。如何获得添加/修改的文件大小、数据和日期?

我可能误解了您的问题,但您使用java的普通文件IO来查找这些信息

下面是我为一张名为cat.jpg的图片查找信息的示例:

File f = new File("/data/cat.jpg");

//Size of file in bytes
Long size = f.length();

//Time of when the file was last modified in microseconds
Long lastModified = f.lastModified();

//The bytes of the file. This gets populated below
byte[] fileData = new byte[(int)f.length()];

try {
    FileInputStream fis = new FileInputStream(f);

    int offset = 0;
    int bytesActuallyRead;

    while( (bytesActuallyRead = fis.read(fileData, offset, 1024)) > 0) {
        offset += bytesActuallyRead;
    }

} catch(Exception e) {

}