wanghuapeng0000 发表于 2013-2-5 01:20:15

java 调用cmd 命令

/** *调用cmd命令 * @author whp * */public class CmdExce {/** * @param args */public static void main(String[] args) {CmdExce d=new CmdExce();d.formatStr();try {Process process=java.lang.Runtime.getRuntime().exec("cmd /c dir ");BufferedReader buffer=new BufferedReader(new InputStreamReader(process.getInputStream()));String str;while((str=buffer.readLine())!=null){System.out.println(str);}} catch (IOException e) {e.printStackTrace();}}/** *String的 format方法 */public void formatStr(){int s=55;String str=String.format("%04d", s);// 不满四位前面补0System.out.println(str);}}
页: [1]
查看完整版本: java 调用cmd 命令