简体   繁体   English

无法写入Android内部存储中的指定路径

[英]Unable to write to specified path in internal storage in android

I am trying to write to a specific path in internal storage in my android app :/data/somefolder but I get the error java.io.filenotfoundexception : Permission denied 我正在尝试在我的Android应用程序中写入内部存储中的特定路径:/ data / somefolder,但出现错误java.io.filenotfoundexception:权限被拒绝

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();
    }

My question is : Is it even possible to write into this folder in android internal storage or does android restrict file creation only to the specific package like /data/data/package/files ? 我的问题是:是否有可能将其写入android内部存储中的此文件夹中,或者android是否仅将文件创建限制为/ data / data / package / files之类的特定包?

I tried using FileOutputStream and the file got created successfully in /data/data/package/files. 我尝试使用FileOutputStream并成功在/ data / data / package / files中创建了文件。

I don't think you can just write into the data dir. 我认为您不能只写入数据目录。 That would require root access. 那将需要root访问。 You can either use the apps internal storage or the external storage (SD card). 您可以使用应用程序的内部存储或外部存储(SD卡)。 Please see here how that works. 在这里查看工作原理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM