How can I set file permissions for files created from Java?

John Mitchell

In pure Java code, you can only specify the read, write, or read & write file modes using the class.

Unfortunately, for operating systems like Linux, that means that you don't have any portable way to distinguish and control the various user classes (i.e., the file's owner, other folks in the owner's "group", or random folks) nor can you deal with things like the "sticky" bit.

The proper way on Unix machines to do this is to set the userMask to the desired value. When JVM is run on Unix box it takes the file permissions from the value of userMask.

About | Sitemap | Contact