4.0讀取文件的報 open failed: ENOENT (No such file or directory)


 

  在android4.0的手機上直接創建某個文件的路徑一直報這個錯:open failed: ENOENT (No such file or directory)

 

   在網上查了很多資料,沒找到解決方案,嘗試了多次終於找到解決辦法

 

  如果在FileOutputStream創建一個流文件路徑時或者是對一個File文件路徑直接操作時,

 

  可先創建文件的路徑,然后在創建文件名就不會在報該錯誤

 

  以下是解決方案:

 

 

 1  public static File getFilePath(String filePath,
 2                                       String fileName) {
 3         File file = null;
 4         makeRootDirectory(filePath);
 5         try {
 6             file = new File(filePath + fileName);
 7         } catch (Exception e) {
 8             // TODO Auto-generated catch block
 9             e.printStackTrace();
10         }
11         return file;
12     }
13 
14     public static void makeRootDirectory(String filePath) {
15         File file = null;
16         try {
17             file = new File(filePath);
18             if (!file.exists()) {
19                 file.mkdir();
20             }
21         } catch (Exception e) {
22 
23         }
24     }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM