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"


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM