简体   繁体   中英

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

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 ?

I tried using FileOutputStream and the file got created successfully in /data/data/package/files.

I don't think you can just write into the data dir. That would require root access. You can either use the apps internal storage or the external storage (SD card). Please see here how that works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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