JAVA传递带有空格的参数

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"

原文地址:https://www.cnblogs.com/jinxingerhuo/p/7662273.html