1

I am trying to add Context.MODE_WORLD_READABLE permission to FileOutputStream(file,append) which is only possible in context.openFileOutput(name,Context.MODE_WORLD_READABLE) but i dont need openFileOutput since I am not able to make sub directories and also i need append mode true.

What can i do???

Thanks In Advance

Padma Kumar
  • 20,420
  • 16
  • 69
  • 127
sheetal
  • 2,934
  • 1
  • 27
  • 44

2 Answers2

0

Instead of using openFileOutput / openFileInput You can access file /directories from internal storage of application sandbox by path like /data/data/(package name) and on this path you can do anything will able to crate directory or files. Also in this scenario you will able to use files writable modes.

Swapnil Deshmukh
  • 665
  • 1
  • 6
  • 23
  • can u show me how can i do that??? coz i could not find any method where i can use Context.MODE_WORLD_READABLE..except openFileOutput – sheetal Sep 21 '12 at 07:08
  • 1
    /data/data/(package name) i dont want path like this but sub paths...like /data/data/folder/subfolder – sheetal Sep 21 '12 at 07:09
  • File file=new File("/data/data/com.example/newfile.txt"); try { file.createNewFile(); FileOutputStream out=new FileOutputStream(file, true); //true will be open file in appended mode out.write("My data".getBytes()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } – Swapnil Deshmukh Sep 21 '12 at 07:21
  • FileInputStream in=new FileInputStream(file); For file reading input stream is used and input stram is only supported with reading thats y it has no mode. You can use writable/append permission while writing file. It will not supported for reading. – Swapnil Deshmukh Sep 21 '12 at 09:32
0

Short answer: Use FileOutputStream as usual, then close it, then call File.setReadable.

Take a look here for more details: java set file permissions to 777 while creating a file object

Community
  • 1
  • 1
Tom Mulcahy
  • 4,149
  • 1
  • 11
  • 5