Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I set the umask from within java?

I'm new to Java. Where is umask exposed in the api?

like image 413
eeee Avatar asked Jul 04 '10 16:07

eeee


People also ask

How do I set umask values?

To determine the umask value you want to set, subtract the value of the permissions you want from 666 (for a file) or 777 (for a directory). The remainder is the value to use with the umask command. For example, suppose you want to change the default mode for files to 644 ( rw-r--r-- ).

Why is umask 0022?

A umask of 022 allows only you to write data, but anyone can read data. A umask of 077 is good for a completely private system. No other user can read or write your data if umask is set to 077. A umask of 002 is good when you share data with other users in the same group.

How do I apply for umask?

The Umask Command Syntaxumask [-p] [-S] [mode] The user file-creation mask is set to mode. If mode begins with a digit, it is interpreted as an octal number; otherwise it is interpreted as a symbolic mode mask similar to that accepted by chmod(1). If mode is omitted, the current value of the mask is printed.


1 Answers

import java.nio.file.Files
import java.nio.file.attribute.PosixFilePermission

File file = new File("/some/path") 
Files.setPosixFilePermissions(file.toPath(), [
                PosixFilePermission.OWNER_READ,
                PosixFilePermission.OWNER_WRITE
            ].toSet())
like image 133
Ich Avatar answered Oct 13 '22 04:10

Ich