java下载bat文件在本地运行的办法?
1个回答
展开全部
12345678910111213141516171819202122 Process process=Runtime.getRuntime().exec("cmd /c run.bat");//要执行的文件的路径为run.bat // 得到输入流 InputStream inputStream=process.getInputStream(); InputStreamReader inputStreamReader=new InputStreamReader(inputStream); BufferedReader bufferedReader=new BufferedReader(inputStreamReader); // 得到输出流 OutputStream outputStream=process.getOutputStream(); OutputStreamWriter outputStreamWriter=new OutputStreamWriter(outputStream); BufferedWriter bufferedWriter=new BufferedWriter(outputStreamWriter); bufferedWriter.write("dd\n"); bufferedWriter.flush(); String temp=null; while((temp=bufferedReader.readLine())!=null) { System.out.println(temp); }}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询