Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
785 views
in Technique[技术] by (71.8m points)

file permissions - How can I set the umask from within java?

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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").


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...