How can I set the umask from within java?

You can’t fiddle with the umask directly, since Java is an abstraction and the umask is POSIX-implementation specific. But you have the following API:

File f;
f.setExecutable(true);
f.setReadable(false);
f.setWritable(true);

There are some more APIs available, check the docs.

If you must have direct access to the umask, either do it via JNI and the chmod() syscall, or spawn a new process with exec("chmod").

Leave a Comment