This question already has an answer here:
Error when trying to execute a command in java [duplicate]
This will not work.
cd is a shell command. And then you create another process to run the java command.
You need a ProcessBuilder. You can set up the initial directory, environment etc:
final File wantedCwd = new File(...); final ProcessBuilder pb = new ProcessBuilder("java", "thefile"); // Change directory pb.directory(wantedCwd);
You can even change the stdin, stdout, stderr etc of the command.
DO NOT use
Runtime.exec(). It won't (
exec()) in many situations.