Change directory and permissions

Posted on 2003-03-14
Medium Priority
Last Modified: 2012-08-14
Hi all,

I need to change directories and edit permissions on a file using java.
I know you have to use the runtime environment but i was just wondering how i would do that.

i need to change directories to /usr/iplanet/servers/docs/scripts
then i need to change permissions on file run.sh to make it executable

Some example code would be helpful


Question by:tommyboy2214
  • 4
LVL 35

Expert Comment

ID: 8136737
 You can use:

  Runtime.getRuntime().exec("chmod -777 /usr/iplanet/server/docs/scripts");

LVL 35

Accepted Solution

girionis earned 500 total points
ID: 8136744

 Runtime.getRuntime().exec("chmod -777 /usr/iplanet/server/docs/scripts/run.sh");

Author Comment

ID: 8136925
thanx alot

Technology Partners: 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!

LVL 35

Expert Comment

ID: 8137078
 Thank you :-) I am glad I helped. Bare in mind though that this will only work under Unix/Linux and not under Windows.

Expert Comment

ID: 8137367
When you take runtime as your solution, you may sacrifice Java's portability by tying your solution specifically to the underline OS structure, for example, UNIX or Windows.

Following is what you need to do.

String userDirectory = "/usr/iplanet/servers/docs/scripts";
String[] command = new String[3];
command[0] = "chmod";
command[1] = "744";
command[2] = userDirectory + "/run.sh";

LVL 35

Expert Comment

ID: 8137442
 Or you can even pass the information through a properties file and load it up using ResourceBundle. Particular useful because you a) maintain java portability and b) you can load thsi info from any class and you do not have to pass it through the command prompt.

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses
Course of the Month12 days, 23 hours left to enroll

580 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