2012-06-08 3 views
2

Dropbox에서 작업 중입니다. 나는 문서를 본다. 이 목록에 표시 내 코드입니다 :Dropbox에서 모든 유형의 파일 다운로드

Entry entryCheck = mApi.metadata("/", 100, null, true, null); 
Log.i("Item Name", entryCheck.fileName()); 
Log.i("Is Folder", String.valueOf(entryCheck.isDir)); 

내가 보관의 모든 목록을 가지고 있지만, 내 질문은 파일이나 디렉토리가 어떻게 경우 여기

  1. 이 entryCheck.isDir 항상 나에게 진정한 가치를 제공한다는 것입니다 내가 어떤 파일인지 또는 어느 것이 디렉토리인지 알 수 있습니까?
  2. 어떻게 파일을 다운로드 했습니까?

이걸로 시도했지만 작동하지 않습니다 :

private boolean downloadDropboxFile(String dbPath, File localFile, 
     DropboxAPI<?> api) throws IOException { 
    BufferedInputStream br = null; 
    BufferedOutputStream bw = null; 
    try { 
     if (!localFile.exists()) { 
      localFile.createNewFile(); // otherwise dropbox client will fail 
      // silently 
     }     

     DropboxInputStream fin = mApi.getFileStream("dropbox", dbPath); 
     br = new BufferedInputStream(fin); 
     bw = new BufferedOutputStream(new FileOutputStream(localFile)); 

     byte[] buffer = new byte[4096]; 
     int read; 
     while (true) { 
      read = br.read(buffer); 
      if (read <= 0) { 
       break; 
      } 
      bw.write(buffer, 0, read); 
     } 
    } catch (DropboxException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } finally { 
     // in finally block: 
     if (bw != null) { 
      bw.close(); 
     } 
     if (br != null) { 
      br.close(); 
     } 
    } 

    return true; 
} 

답변

1

이이 파일을 다운로드

String inPath ="mnt/sdcard/"+filename; 
File file=new File(inPath);   
try { 

    mFos = new FileOutputStream(file); 
} catch (FileNotFoundException e) { 
    mErrorMsg = "Couldn't create a local file to store the image"; 
    return false; 
} 

mApi.getFile("/"+filename, null, mFos, null); 

작업과 sdcard에 위치 inPath에 저장됩니다. 메인 스레드가 아닌 새 스레드에서 수행해야합니다. AsyncTask를 사용하십시오. http://www.androiddesignpatterns.com/2012/06/app-force-close-honeycomb-ics.html 이유를 설명하는 링크입니다 ..

관련 문제