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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


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

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.

Question has a verified solution.

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

Suggested Solutions

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

752 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