2014-04-13 77 views
1

我能從保存箱中的特定路徑獲取所有文件夾。但現在我想從任何特定的FOLDER獲取所有文件。就像在收件箱中有一個名爲「MyFolder1」的FOLDER一樣,現在我想從此FOLDER獲取所有文件。那麼,我怎樣才能完成這項任務。如何從保存箱中的特定文件夾中獲取文件

回答

1
private boolean downloadDropboxFile(String dbPath, File localFile) throws IOException{ 

     BufferedInputStream br = null; 
     BufferedOutputStream bw = null; 

     try { 
      if (!localFile.exists()) { 
       localFile.createNewFile(); //otherwise dropbox client will fail silently 
      } 

      FileDownload fd = api.getFileStream("dropbox", dbPath, null); 
      br = new BufferedInputStream(fd.is); 
      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); 
      } 
     } finally { 
      //in finally block: 
      if (bw != null) { 
       bw.close(); 
      } 
      if (br != null) { 
       br.close(); 
      } 
     } 

     return true; 
    } 

來源:http://forums.dropbox.com/topic.php?id=23189&replies=5#post-159521

0

我自己得到了解決。

String mPath="/"; //You can change the path here to specific FOLDER 
Entry dirent = null; 
try 
    { 
     dirent = mApi.metadata(mPath, 1000, null, true, null);    
    } 
catch (DropboxException e) 
    { 
    System.out.println("Error Detail "+e.getMessage()); 
    } 

//執行一個循環,並從PATH

 for (Entry ent: dirent.contents) 
    { 
     String name = ent.fileName();       
     System.out.println("My File in Folder "+name);       
     } 
檢索的所有文件和文件夾
相關問題