如何告诉java忽略空格

时间:2021-10-24 20:33:59

I have a string that I am trying to execute. The string contains a path to a MacOS .x file, which has a space in the path name. When I run it Java is telling me that it cannot run the program.

我有一个我想要执行的字符串。该字符串包含MacOS .x文件的路径,该文件在路径名中有一个空格。当我运行它时,Java告诉我它无法运行程序。

"/Users/brianallison/Documents/Java/RELAP5 GUI/issrs/dist/relap5.x" -i "Choose your input file" -r "" -o ""

May 08, 2015 2:19:37 PM my.issrs.issrsUI btnRunRelapActionPerformed SEVERE: null java.io.IOException: Cannot run program "/Users/brianallison/Documents/Java/RELAP5": error=2, No such file or directory

2015年5月8日下午2:19:37 my.issrs.issrsUI btnRunRelapActionPerformed SEVERE:null java.io.IOException:无法运行程序“/ Users / brianallison / Documents / Java / RELAP5”:error = 2,没有这样的文件或目录

I have tried putting quotes around the path, but Java is ignoring the quotes. As you can see on the first line that is how it supposed to go, but Java is cutting it off at RELAP5.

我试过在路径上添加引号,但Java忽略了引号。你可以在第一行看到它应该如何发展,但Java正在RELAP5中将其切断。

1 个解决方案

#1


Try to escape space with back slash:

尝试使用反斜杠来逃避空间:

"/Users/brianallison/Documents/Java/RELAP5\ GUI/issrs/dist/relap5.x" -i "Choose your input file" -r "" -o ""

#1


Try to escape space with back slash:

尝试使用反斜杠来逃避空间:

"/Users/brianallison/Documents/Java/RELAP5\ GUI/issrs/dist/relap5.x" -i "Choose your input file" -r "" -o ""