On unix-like systems, each process has an umask property, which is masked by the permissions of any file created and inherited by child processes. the default is 0002
or "turn off recording for others." Therefore, most likely, Java sets the permission requested by you, and then it is masked . You can explicitly set permissions after creating the file or change the umask settings in the java process before it starts.
First, let's look at the current umask:
arthur@a :/tmp$ umask 0002
and then create a read and write file for everyone (tap this as well as your Java code)
arthur@a :/tmp$ touch foo arthur@a :/tmp$ ls -l foo -rw-rw-r-- 1 arthur arthur 0 Aug 28 13:58 foo
we see that octal 0002
was masked from the actual file permissions.
Therefore, we can remove this umask by setting it to 0000:
arthur@a :/tmp$ umask 0000 arthur@a :/tmp$ touch foo
And we see that foo remains the same as during the upgrade, since umasks only apply to new files. and a new file line is created using read permission.
arthur@a :/tmp$ ls -l foo -rw-rw-r-- 1 arthur arthur 0 Aug 28 14:00 foo arthur@a :/tmp$ touch bar arthur@a :/tmp$ ls -l bar -rw-rw-rw- 1 arthur arthur 0 Aug 28 14:00 bar
I have the habit of setting permissions explicitly after creating the file in Java, because it is easier to transfer from system to system. * You can prove it yourself by installing umask in your shell before starting emacs / your- programs and checking file permissions after.
* Java is "write, ever run anywhere", and ??
source share