0
我非常困惑,我嘗試了幾件事:我想從FireBase下載一個純文本文件到我的本地臨時文件空間。這工作完美。現在我想在我的外部類中使用此文件的全部文本。 我該怎麼做?Android:FireBase存儲:將json文件作爲臨時文件下載
這裏我的代碼片段:
private void getFireBaseStorage() {
FirebaseStorage storage =
FirebaseStorage.getInstance();
StorageReference storageRef =
storage.getReferenceFromUrl("gs://URL")
.child("filename.json");
try {
final File localFile = File.createTempFile("file", "json");
storageRef.getFile(localFile).addOnSuccessListener(new OnSuccessListener<FileDownloadTask.TaskSnapshot>() {
@Override
public void onSuccess(FileDownloadTask.TaskSnapshot taskSnapshot) {
Log.i("FireBase", "File is present " + Long.toString(localFile.length()));
try {
FileReader fr = new FileReader(localFile);
BufferedReader br = new BufferedReader(fr);
String sCurrentLine;
while ((sCurrentLine = br.readLine()) != null) {
mJSONReturnValue += sCurrentLine;
}
System.out.println(mJSONReturnValue);
} catch (IOException exception) {
exception.printStackTrace();
}
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
Log.i("FireBase", "File is not there");
}
});
// Log.i("FireBase", result.());
} catch (IOException ioexception) {
ioexception.printStackTrace();
}