【问题标题】:Unable to write to specified path in internal storage in android无法写入android内部存储中的指定路径
【发布时间】:2014-08-20 06:10:22
【问题描述】:

我正在尝试在我的 android 应用程序中写入内部存储中的特定路径:/data/somefolder 但我收到错误 java.io.filenotfoundexception : Permission denied

String testString="Hello World!";
    File newFile=new File("/data/somefolder/testFile.txt");
    try{
        OutputStream myOut=new BufferedOutputStream(new FileOutputStream(newFile,true));
        myOut.write(testString.getBytes());
        myOut.flush();
        myOut.close();
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

我的问题是:是否甚至可以在 android 内部存储中写入此文件夹,或者 android 是否仅将文件创建限制为特定包,例如 /数据/数据/包/文件?

我尝试使用 FileOutputStream 并在 /data/data/package/files 中成功创建了文件。

【问题讨论】:

    标签: java android


    【解决方案1】:

    我认为您不能只写入数据目录。那将需要root访问权限。您可以使用应用程序内部存储或外部存储(SD 卡)。请参阅here 是如何工作的。

    【讨论】:

    • 如果您有完整的 root 访问权限,您将不会收到 Permission denied 异常。仅仅因为您拥有 root 访问权限并不意味着您的应用也拥有它,或者您对此有把握吗?
    • 我如何知道我的应用是否有 root 访问权限?
    • 这可能会有所帮助:stackoverflow.com/questions/21596397/…
    猜你喜欢
    • 1970-01-01
    • 2013-11-28
    • 1970-01-01
    • 1970-01-01
    • 2016-09-26
    • 1970-01-01
    • 2012-08-11
    • 2011-06-12
    • 2014-11-12
    相关资源
    最近更新 更多