I am writing a small Java Application and I am having problems with a filepath.
I want to execute a batch file with
Runtime.getRuntime().exec("cmd /c start c:\program files\folder\file.bat");
But now Java cries because of the whitespace in the filepath.
How can I escape it?
EDIT:
Ok, thank you for the answers guys.
But I just ran into a new problem:
If I start the .bat this way it just opens a cmd window and nothing happens. But if I move the .bat into c:/folder/ without spaces it works…the .bat itself is fine too.
You can avoid any problems like this by using the Runtime#exec that takes a String[]:
That way you don’t have to worry about quoting the file names. However, you still have to worry about quoting \ in the file names.