I stumbled upon something really weird in the code down below. I want to open a *.pdf file in Java, using the Runtime.getRuntime().exec("some command").waitFor();
statement.
public static void main(String[] args) {
File file = new File("C:\\test123.pdf");
try {
Runtime.getRuntime()
.exec("rundll32 url.dll,FileProtocolHandler " + file.toString())
.waitFor();
}
catch (IOException e) {
// do something
}
catch (InterruptedException e) {
// do something
}
}
Now when the path contains single spaces, like
new File("C:\this is a test.pdf)it works fine, but if I add a second space on some place, like
new File("C:\two spaces")it does not work, but it also does not give a warning or error at runtime. It just doesn't do anything...
First of all, can somebody explain why this not works? And second, is it possible to fix this, and if so how (but not a solution like ''remove the second space'')?
Thanks a lot for helping me out!