0

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.

1 Answers1

0

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.

SimonSays
  • 10,867
  • 7
  • 44
  • 59
  • If you had complete root access, you would not get a Permission denied exception. Just because YOU have root access does not mean that your app has it as well, or are you sure about that? – SimonSays Aug 19 '14 at 22:23
  • how will i know if my app has root access? – girlwhocodes Aug 19 '14 at 22:37
  • This might help: http://stackoverflow.com/questions/21596397/getting-root-permission-for-android-app – SimonSays Aug 19 '14 at 22:48