2011-04-18 2 views
2

콘텐츠 : URI의 경우 ContentProvider/Contentresolver를 사용하여 수정 된 날짜, 크기 및 데이터에 대한 정보를 검색했습니다. URI를하지만 난 다음 코드를하려고 할 때 : 나는 파일에 대해 동일한 작업을 수행하고자하는파일에 대한 정보 쿼리 android

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

커서가 null로 반환됩니다. 파일 크기, 데이터 및 날짜를 ​​추가/수정하는 방법은 무엇입니까?

답변

1

질문에 대한 오해가있을 수 있지만 java의 일반 파일 IO를 사용하여 해당 정보를 찾을 수 있습니다.

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) { 

} 
: 여기

은 사진이라는 cat.jpg에 대한 정보를 알아내는 날의 예입니다
관련 문제