对于内容:URI,我使用ContentProvider / Contentresolver来检索有关修改日期,大小和数据的信息。我想对file:URI执行相同的操作,但是当我尝试以下代码时:
CursorLoader loader = new CursorLoader(this, uri, proj, null, null, null);
Cursor cursor = loader.loadInBackground();
Cursor返回null。如何获取/修改文件大小,数据和日期?
答案 0 :(得分: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) {
}