首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

java急需关注的知识点-I0之进程控制

2012-09-02 
java需要关注的知识点---I0之进程控制进程控制:public class OSExecute {public static void command(Stri

java需要关注的知识点---I0之进程控制
进程控制:

public class OSExecute {public static void command(String command) {boolean err = false;try {Process process = new ProcessBuilder(command.split(" ")).start();BufferedReader result = new BufferedReader(new InputStreamReader(process.getInputStream()));String s;while((s = result.readLine())!= null) {System.out.println(s);}BufferedReader errors = new BufferedReader(new InputStreamReader(process.getErrorStream()));while((s = errors.readLine())!= null) {System.err.println(s);err = true;}} catch (IOException e) {if(!command.startsWith("CMD /C"))command("CMD /C" + command);elsethrow new RuntimeException(e);}if (err) {throw new OSExecuteException("Errors executing " + command);}}}

热点排行