Java调用Windows批处理
有时候,JAVA程序需调用本地的批处理进行一些处理,下面的代码就演示了如何在JAVA中调用本地的批处理文件,如下import java.io.BufferedReader;import java.io.InputStreamReader;/** * @author Dao */public class Test{ public static void main(String[] args){ Process process; try { process = Runtime.getRuntime().exec("c:\\1.bat"); BufferedReader read = new BufferedReader(new InputStreamReader( process.getInputStream())); String str = null; while ((str = read.readLine()) != null) { System.out.println(str); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); }}}
页:
[1]