Android 查询有关文件的信息
对于content:URI,我使用ContentProvider/Contentresolver检索有关修改日期、大小和数据的信息。我希望对file:URI执行相同的操作,但在尝试以下代码时: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。如何获得添加/修改的文件大小、数据和日期?我可能
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) {
}