这是我通常用来执行快捷方式文件(.lnk)的代码
String currentDir = new File(game.getGamePath()).getCanonicalPath();
currentDir = currentDir.substring(0, currentDir.lastIndexOf("\\") + 1) + '"' +
currentDir.substring(currentDir.lastIndexOf("\\") + 1, currentDir.length()) + '"';
ProcessBuilder processBuild = new ProcessBuilder();
processBuild.command("cmd", "/c", "start" ,"/wait", "", currentDir);
Process = processBuild.start();
try {
Process.waitFor();
} catch (InterruptedException ex) {
}
问题是当快捷方式文件名有空格时,我从窗口收到一个错误,说
无法加载[WordAfterSpace.ink]
例如,假设我有一个currentDir,值为[Desktop\a B.lnk]
经过分析,它将是[Desktop\“A.B.ink”],这在命令提示符下非常有效。
问题是,如果我使用上面的代码,我会得到这个错误:
Windows找不到“B.ink”,请确保键入的名称正确,然后重试