You can't (usefully) issue a cd
command through Runtime.exec
. The cd
command, on most OS's, is a built-in command of the shell, not an executable (which is why you get the error you get), and it operates on the runtime environment of the shell. Although you could use Runtime.exec
to fire up a shell and execute the cd
command within it (for Windows that would be cmd.exe /c "cd path"
), it would only change the current directory within the shell, not for the program running.
What you need to do is resolve the directory within your program, using the various features of File
, and use that resolved absolute file path for whatever it is that you're trying to use cd
for.
If you post a (new) question saying what it is you're trying to achieve by using cd
, we can help you achieve that, but using Runtime.exec
to issue cd
isn't going to be the solution.