我正在尝试从Firebase存储下载pdf文件,但是它不起作用。遵循代码:
holder.itemView.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
try {
File rootPath = new File(Environment.getExternalStorageDirectory(), "file_name");
if(!rootPath.exists()) {
rootPath.mkdirs();
}
final File file = new File(rootPath, lista.get(position).getNome()+".pdf");
storageRef.getFile(file).addOnSuccessListener(new OnSuccessListener<FileDownloadTask.TaskSnapshot>() {
@Override
public void onSuccess(FileDownloadTask.TaskSnapshot taskSnapshot) {
}
});
}catch(Exception e){
}
}});
我得到的例外是:
E/FileDownloadTask: Exception occurred during file write. Aborting.
java.io.IOException: No such file or directory
at java.io.UnixFileSystem.createFileExclusively0(Native Method)
at java.io.UnixFileSystem.createFileExclusively(UnixFileSystem.java:281)
at java.io.File.createNewFile(File.java:1000)
at com.google.firebase.storage.FileDownloadTask.zza(Unknown Source:75)
at com.google.firebase.storage.FileDownloadTask.run(Unknown Source:190)
at com.google.firebase.storage.zzr.run(Unknown Source:2)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)
E/StorageException: StorageException has occurred.
An unknown error occurred, please check the HTTP result code and inner exception for server response.
Code: -13000 HttpResult: 200
我将这些设置为清单文件中的必需权限:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />