从 box.com 下载文件时出现异常 - 安卓



我正在尝试使用Box android SDK下载文件。问题似乎出在目标文件参数上。box.com 调用是检查目标文件是否存在 - 但为什么?我得到java.io.FileNotFoundException。

destinationFile = new File(getFilesDir(), "myfile.crs");
// destinationFile = new File(getFilesDir(),"/");
try {
BoxDownload fileDownload = mFileApi.getDownloadRequest(destinationFile, fileID)
// Optional: Set a listener to track download progress.
.setProgressListener(new ProgressListener() {
@Override
public void onProgressChanged(long numBytes, long totalBytes) {
// Update a progress bar, etc.
}
})
.send();
} catch (BoxException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

执行所有检查

Log.i(getClass().getName(),"Does File exists:"+(destinationFile.exists()?"Yes":"No"));
Log.i(getClass().getName(),"Is it A file:"+(destinationFile.isFile()?"Yes":"No"));
Log.i(getClass().getName(),"Is it Writable:"+(destinationFile.canWrite()?"Yes":"No"));
Log.i(getClass().getName(),"Is it A Readable:"+(destinationFile.canRead()?"Yes":"No"));
Log.i(getClass().getName(),"Path:"+destinationFile.getAbsolutePath());

您最有可能发现文件不存在,然后在使用它之前执行此操作。

if(!destinationFile.exists()){
try {
destinationFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}

答案是创建一个新文件。然后在 File 实例上调用 .createNewFile((。然后调用我发布的所有代码,除了在后台运行它。这就是我在这里问的原因 - 我想知道我是否为 Android 做了不正确的事情,我是。盒子网络操作需要在线程上完成。 太糟糕了,他们从不显示这个来下载文件。太糟糕了,没有一个在网络上使用Android DSK下载文件的示例。

最新更新