如何从Dropbox中的特定文件夹中获取文件

时间:2014-04-13 12:30:57

标签: android dropbox

我可以从dropbox的特定路径获取所有FOLDERS。但现在我想从任何特定的文件夹中获取所有文件。就像有一个名为" MyFolder1"在Dropbox中,现在我想从这个FOLDER获取所有文件。那么,我怎样才能完成这项任务。

2 个答案:

答案 0 :(得分: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

答案 1 :(得分: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);                        
      }