2011-04-18 56 views
2

对于content:URI,我使用ContentProvider/Contentresolver检索有关修改日期,大小和数据的信息。我想为file:URI做同样的事情,但是当我尝试下面的代码时:查询有关文件的信息android

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

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

回答

1

我可能会误解你的问题,但你使用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) { 

}