Android 从Dropbox下载所有类型的文件
我正在做Dropbox。我看到文件了。这是我要显示列表的代码:Android 从Dropbox下载所有类型的文件,android,download,dropbox,Android,Download,Dropbox,我正在做Dropbox。我看到文件了。这是我要显示列表的代码: Entry entryCheck = mApi.metadata("/", 100, null, true, null); Log.i("Item Name", entryCheck.fileName()); Log.i("Is Folder", String.valueOf(entryCheck.isDir)); 我从dropbox得到了所有列表,但我的问题是 这里entryCheck.isDir总是给我真实值,如果它是文件或目
Entry entryCheck = mApi.metadata("/", 100, null, true, null);
Log.i("Item Name", entryCheck.fileName());
Log.i("Is Folder", String.valueOf(entryCheck.isDir));
我从dropbox得到了所有列表,但我的问题是
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;
}
private boolean downloadDropboxFile(字符串dbPath,文件localFile,
DropboxAPI)引发IOException{
BufferedInputStream br=null;
BufferedOutputStream bw=null;
试一试{
如果(!localFile.exists()){
localFile.createNewFile();//否则dropbox客户端将失败
//默默地
}
DropboxInputStream fin=mApi.getFileStream(“dropbox”,dbPath);
br=新的BufferedInputStream(fin);
bw=新的BufferedOutputStream(新的FileOutputStream(localFile));
字节[]缓冲区=新字节[4096];
int-read;
while(true){
read=br.read(缓冲区);
如果(读取这将起作用
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);
这将下载文件并将其存储在SD卡位置inPath
。
您必须在新线程中执行此操作,而不是在主线程中。请使用AsyncTask。
这个链接解释了原因