【问题标题】:Android File open failed: EROFSAndroid 文件打开失败:EROFS
【发布时间】:2013-08-24 13:07:37
【问题描述】:

有时我得到 Exception.java.io.FileNotFoundException,文件打开失败:EROFS(只读文件系统)。我的清单中有 WRITE_EXTERNAL_STORAGE 权限,偶尔当我运行我的服务时,我会遇到这些异常,并且很少有操作不会成功,但是如果我重新启动我的设备,它就可以正常工作。 我想捕获“Exception.java.io.FileNotFoundException”异常并以编程方式重新启动我的设备。我的设备已植根,因此我以编程方式执行“su -c reboot”。

我需要知道如何捕捉“文件打开失败:EROFS”异常并触发重启??

【问题讨论】:

  • 该异常并不意味着没有要打开的文件?无论如何,包含将引发异常的代码部分怎么样? try{your code}catch(FileNotFoundException e){reboot here?} 应该可以完成这项工作。

标签: android file exception


【解决方案1】:

将解决您的问题:

    try{
        do whatever
    }catch(FileNotFoundException ex){
        if("EROFS ( Read- only file System)".equals(ex.getMessage())){
           call code for reboot 
        }
    }

您可以替换错误消息甚至跳过它

编辑:- 基于评论

    try{
        do whatever
    }catch(IOException ex){
        if((ex instanceof FileNotFoundException) &&  "EROFS ( Read- only file System)".equals(ex.getMessage())){
           call code for reboot 
        }
    }

【讨论】:

  • 上面的代码对我有用,但我需要在我的代码中的很多地方捕捉到那个异常。如果我想使用“extends FileNotFoundException class”那么我怎样才能捕捉到那个异常
  • 比抓住他的父母 IOException docs.oracle.com/javase/7/docs/api/java/io/… 并按upvote,如果我有帮助,谢谢
  • 是这样吗???
     导入 java.io.IOException;公共类 FileNotFoundException 扩展 IOException { public FileNotFoundException() { super(); If ("EROFS ( 只读文件系统)".equalsIgnoreCase( getMessage() ) ) { // 重启 } } 覆盖 public String getMessage() { return super.getMessage(); } } 
  • @user1810931 没有。我会更新我的答案,Android API 不会抛出您的自定义异常,请参阅更新版本(编辑后)
猜你喜欢
  • 2014-06-01
  • 2016-01-23
  • 2015-06-08
  • 2015-01-22
  • 1970-01-01
  • 2015-01-02
  • 2014-04-19
  • 2019-09-30
  • 2012-12-08
相关资源
最近更新 更多