Dave's Brain

Browse - Programming Tips - How can I make a file or folder world readable?

Date: 2017jan19
OS: Android
Keywords: directory

Q.  How can I make a file or folder world readable?

A.  At or after OS Level 9 use setReadable:

boolean makeWorldReadable(final String filename) { File f = new File(filename); return f.setReadable(true, false); }
Before OS Level 9, use chmod:
boolean chmod(final String file, final int mode) { final String strMode = String.format("%o", mode); boolean result = false; try { Process p = Runtime.getRuntime().exec("chmod " + strMode + " " + file); result = true; } catch (IOException e) { result = false; } return result; }
Example use for a file:
chmod("myfile.txt", 0666);
Example use for a folder:
chmod("myfolder", 0777);

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.