我正在从Dropbox上传和下载文件。当我上传一个文件时,它会正确地上传。但是当我下载一个文件并打开它时,文件大小为零字节。有人可以告诉我这是为什么吗?
下载代码:
下载代码:
try {
File localFile = new File(localFilePath);
File fileSelected = new File(dropboxPath);
if (!localFile.exists()) {
localFile.createNewFile();
} else {
//copy(fileSelected, localFile);
//mApi.copy("/Test/test.png", "/sdcard/testfile.png");
BufferedInputStream br = null;
BufferedOutputStream bw = null;
DropboxInputStream fd;
try {
fd = mApi.getFileStream(fileSelected.getPath(), null);
br = new BufferedInputStream(fd);
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) {
e.printStackTrace();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (bw != null) {
try {
bw.close();
if (br != null) {
br.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}/*
else {
showToast("File already exists");
}*/
}
catch (IOException e) {
showToast("Exception");
e.printStackTrace();
}
catch (Exception e) {
showToast("Exception");
e.printStackTrace();
}
close()
。 - Simontry
块,但没有展示catch/finally
- 缺少信息会使调试变得困难。 - ataulm