【发布时间】:2020-04-02 15:53:19
【问题描述】:
我正在尝试下载名为 1.pdf、2.pdf 的 Firebase 存储目录中的所有文件... 该代码在调试模式下工作,但在发布时不起作用。我整天都被困在这上面。 我认为它可能是来自另一个类的线程,但老实说我不知道。
从 Firebase 获取文件的代码:
for (int i = 1; i < 10000; i++) {
StorageReference ref = storageRef.child("FirstTimeForms/" + i + ".pdf");
File localFile = File.createTempFile("Form", ".pdf");
FileDownloadTask dm = ref.getFile(localFile);
int fileSize = Integer.parseInt(String.valueOf(localFile.length()/1024));
if(fileSize > 0){
fileManager.copyFile(localFile, new File("/sdcard/Download/Forms/" + i + ".pdf"));
}else{
return;
}
}
将从缓存下载的文件复制到 SD 的代码
FileChannel inChannel = new FileInputStream(src).getChannel();
FileChannel outChannel = new FileOutputStream(dst).getChannel();
try
{
inChannel.transferTo(0, inChannel.size(), outChannel);
}
finally
{
if (inChannel != null)
inChannel.close();
if (outChannel != null)
outChannel.close();
}
【问题讨论】:
标签: java android firebase firebase-storage