0

I am trying to change current working directory in unix using Java , but it's not working

Here is my sample:

  1. The current working directory is /temp/input
  2. I want to change the directory to /test/output
  3. And create new folder using mkdir
String[] commands = new String [] {"bash", "-c", "mkdir temp"};
Runtime.getRuntime().exec(commands,null,new File("/test1/output"));
octano
  • 851
  • 1
  • 10
  • 18
Rajeev
  • 87
  • 1
  • 9
  • You can use java capability to create a folder. See answer - https://stackoverflow.com/questions/3634853/how-to-create-a-directory-in-java. You can just pass your path as a parameter – Pizza eu Oct 23 '18 at 07:47
  • If all you're after is file/directory manipulation, I'd advise you to check the [Files](https://docs.oracle.com/javase/7/docs/api/java/nio/file/Files.html) and [Paths](https://docs.oracle.com/javase/7/docs/api/java/nio/file/Paths.html) APIs instead. – Jaims Oct 23 '18 at 07:48
  • thanks for your reply, agree, but it will not work in case of other unix commands such as tar, cp etc. Here am facing issue while changing directory. – Rajeev Oct 23 '18 at 07:50

0 Answers0