请帮助编写一个模式以仅在命令及其参数之间的空格上拆分命令行:
我的代码:
String commands = "gedit /home/ant/Documents/Txt Books/1.txt /home/ant/Documents/1.txt";
String[] arrCommands = Pattern.compile("\\\s[^\\\s\\\w]").split(commands);
for (int i = 0; i < arrCommands.length; i++) {
System.out.println(arrCommands[i]);
}
程序给出以下结果:
gedit
home/ant/Documents/Txt Books/1.txt
home/ant/Documents/1.txt
并且有必要这样做:
gedit
/home/ant/Documents/Txt Books/1.txt
/home/ant/Documents/1.txt