Directory Permissions problem when using mkdir() of the File class

Posted on 2008-06-17
Last Modified: 2013-12-29

I hava a Java application that creates directories using the mkdir() method of the File class. This is in UNIX. when the directory is created by madir() it has drwxr-xr-x permissions string by default. As you can see the user has r/w/ex permissions, and the group has only r/ex permissions and does not have 'write' permissions. Our requirement is, when this directory is created, we must give permissions to the group also for writing.

Since mkdir() defaults to drwxr-xr-x, how can I set the peremissions to be drwxrwxr-x so that the group will also have write permissions when the directory is created.

Question by:prain
  • 4
  • 3
LVL 86

Accepted Solution

CEHJ earned 250 total points
ID: 21802206
Two ways i can think of

1. set the umask of the shell in which the java app is running to 0002 (man umask)
2. Runtime.exec a chmod after the fact

Author Comment

ID: 21802333
is'nt there a direct Java way of doing that?
LVL 86

Expert Comment

ID: 21802378
No. Java is platform independent, so would have no platform-dependent way of altering file perms
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.


Author Comment

ID: 21802391
Ok. That' right. I will try this.

Author Closing Comment

ID: 31467929
OK. That works Great!.  Thanks.
LVL 86

Expert Comment

ID: 21803985

Which way did you go in the end?

Author Comment

ID: 21807006
I set the permissions using chmod 775  by Runtime.exe();

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MySqlDump not dumping triggers 1 43
SequenceInputStream example 3 19
Why doesn't this text field show up on my Applet frame? 2 20
Java basic valueOf question 1 29
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question