我在下面的代码中偶然发现了一些非常奇怪的东西。我想使用该Runtime.getRuntime().exec("some command").waitFor();
语句在 Java 中打开一个 *.pdf 文件。
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
}
}
现在当路径包含单个空格时,例如
new File("C:\this is a test.pdf)它工作正常,但如果我在某个地方添加第二个空间,比如
new File("C:\两个空格")它不起作用,但它也不会在运行时发出警告或错误。它只是没有做任何事情......
首先,有人可以解释为什么这不起作用吗?其次,是否有可能解决这个问题,如果可以的话(但不是像''删除第二个空格''这样的解决方案)?
非常感谢您帮助我!