2016-07-13 11 views
0

firebaseを使用してファイルをダウンロードしています。以下のコードは、ファイルをルートディレクトリにダウンロードします。私が欲しいのは、ルートディレクトリにフォルダを作成し、そこにダウンロードしたファイルを保存することです。フォルダを作成してファイルを保存します

FirebaseStorage storage = FirebaseStorage.getInstance(); 
        StorageReference storageRef = storage.getReferenceFromUrl("gs://fir-896a6.appspot.com"); 

        StorageReference islandRef = storageRef.child(fileName); 
        File localFile = null; 
        try { 
         localFile = new File(Environment.getExternalStorageDirectory(), fileName); 
        } catch (Exception e) { 
         e.printStackTrace(); 
        } 
        islandRef.getFile(localFile); 

私はそれはしかし、代わりにファイルをダウンロードし、フォルダに保存するフォルダー学生ポータルを作る

localFile = new File(Environment.getExternalStorageDirectory() + "/Student Portal/", fileName); 
         localFile.mkdirs(); 

使用して試してみましたが、それは学生ポータルフォルダfilenameという名前の内部のフォルダを作成し、エラーをスローします

E/FileDownloadTask: Exception occurred during file download 
                        java.io.FileNotFoundException: /storage/emulated/0/Student Portal/proposal-1.docx: open failed: EISDIR (Is a directory) 
                         at libcore.io.IoBridge.open(IoBridge.java:456) 
                         at java.io.FileOutputStream.<init>(FileOutputStream.java:87) 
                         at java.io.FileOutputStream.<init>(FileOutputStream.java:72) 
                         at com.google.firebase.storage.FileDownloadTask.run(Unknown Source) 
                         at com.google.firebase.storage.StorageTask$5.run(Unknown Source) 
                         at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 
                         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 
                         at java.lang.Thread.run(Thread.java:818) 
                        Caused by: android.system.ErrnoException: open failed: EISDIR (Is a directory) 
                         at libcore.io.Posix.open(Native Method) 
                         at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186) 
                         at libcore.io.IoBridge.open(IoBridge.java:442) 
                         at java.io.FileOutputStream.<init>(FileOutputStream.java:87)  
                         at java.io.FileOutputStream.<init>(FileOutputStream.java:72)  
                         at com.google.firebase.storage.FileDownloadTask.run(Unknown Source)  
                         at com.google.firebase.storage.StorageTask$5.run(Unknown Source)  
                         at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)  
                         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)  
                         at java.lang.Thread.run(Thread.java:818)  
07-13 21:14:39.217 14894-15750/com.horngmail.invisible.firebase 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 
07-13 21:14:39.217 14894-15750/com.horngmail.invisible.firebase E/StorageException: /storage/emulated/0/Student Portal/proposal-1.docx: open failed: EISDIR (Is a directory) 
                        java.io.FileNotFoundException: /storage/emulated/0/Student Portal/proposal-1.docx: open failed: EISDIR (Is a directory) 
                         at libcore.io.IoBridge.open(IoBridge.java:456) 
                         at java.io.FileOutputStream.<init>(FileOutputStream.java:87) 
                         at java.io.FileOutputStream.<init>(FileOutputStream.java:72) 
                         at com.google.firebase.storage.FileDownloadTask.run(Unknown Source) 
                         at com.google.firebase.storage.StorageTask$5.run(Unknown Source) 


                       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 
                        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 
                        at java.lang.Thread.run(Thread.java:818) 


            Caused by: android.system.ErrnoException: open failed: EISDIR (Is a directory) 
                       at libcore.io.Posix.open(Native Method) 
                       at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186) 
                       at libcore.io.IoBridge.open(IoBridge.java:442) 

答えて

1
localFile.mkdirs(); 

への変更
localFile.getParentFile().mkdirs(); 

まず、fileNameでそのディレクトリを削除します。

関連する問題