1

I was trying to run this code on Linux as a normal user but due to insufficient privileges listfiles() returning null.

File parentDirectory = new File("/root");
File[] childFiles = parentDirectory.listFiles();

How can I run the above code without running java application in SU mode.

  • Can I ask the user to enter root password? So that I can run linux commands instead of java functions.

What all options I have to achieve this in java?

Vasant
  • 301
  • 4
  • 14
  • 1
    I assume that you already checked http://stackoverflow.com/questions/11143027/java-execute-linux-commands-that-require-su – Arun Manivannan Oct 29 '12 at 16:11
  • You can let java run a skript from the user with execution rights for you, created by the root admin. - *if that is feasible* – Joop Eggen Oct 29 '12 at 16:13

1 Answers1

0

You can make the /root/ directory world-readable or group-readable. In the latter case, you must also add the user running the program to the appropriate group.

World readable:

sudo chmod o+r /root

Group readable:

sudo chmod g+r /root
Kim Stebel
  • 41,826
  • 12
  • 125
  • 142