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

在android4.0的手机上直接创建某个文件的路径一直报这个错:open failed: ENOENT (No such file or directory).
在网上查了很多资料,没找到解决方案,尝试了多次终于找到解决办法:
  如果在FileOutputStream创建一个流文件路径时或者是对一个File文件路径直接操作时,可先创建文件的路径,然后在创建文件名就不会在报该错误
  以下是解决方案:

[html]  view plain copy
  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.     }  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值