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