JAVA传递带有空格的参数

时间:2017-10-13 18:40:59   收藏:0   阅读:483
1 String s="b2 + b1";
2 Process child = Runtime.getRuntime().exec("C:\\eclipse-workspace\\beam\\exe\\bandmath\\BandMath.exe"+" \""+s+"\"); 

 

当java传递有空格的代码时s是有空格的参数 需要将" "+s+" "改为

+" \""+s+"\"这样才不会将s里面的空格参数识别为参数之间的空格
 1 public class cal {
 2      public static void main(String[] args) 
 3      {   
 4         String s="B1 + B2";
 5         String s1="B3+B4";
 6         
 7         System.out.println(s1+" "+s);
 8         System.out.println(s1+" \""+s+"\" ");
 9      }
10 }

输出:

B3+B4 B1 + B2
B3+B4 "B1 + B2"

原文:http://www.cnblogs.com/jinxingerhuo/p/7662273.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!