我希望使用Java DropBox API下载我的Dropbox账户中的文件。我尝试使用以下代码,但是它显示文件和文件夹列表,而我想要将文件下载到我的系统中。请问如何实现?
以下是我的代码:
以下是我的代码:
Scanner tokenScanner = new Scanner(tokensFile);
String ACCESS_TOKEN_KEY = tokenScanner.nextLine(); // Read key
String ACCESS_TOKEN_SECRET = tokenScanner.nextLine(); // Read secret
tokenScanner.close(); //Close Scanner
//Re-auth
AccessTokenPair reAuthTokens = new AccessTokenPair(ACCESS_TOKEN_KEY,ACCESS_TOKEN_SECRET);
mDBApi.getSession().setAccessTokenPair(reAuthTokens);
Entry entries = mDBApi.metadata("/", 20, null, true, null);
for (Entry e: entries.contents) {
if(!e.isDeleted){
if(e.isDir){
System.out.println("Folder ---> " + e.fileName() );
} else {
// this will download the root level files.
System.out.println("File ---->" + e.fileName());
DropboxInputStream inputStream = mDBApi.getFileStream(e.path,null);
OutputStream out=new FileOutputStream(e.fileName());
byte buf[]=new byte[1024];
int len;
while((len=inputStream.read(buf))>0)
out.write(buf,0,len);
out.close();
inputStream.close();
System.out.println("File is created....");