Process process;  
        String cmd = "/home/ty/t.sh";//这里必须要给文件赋权限 chmod u+x fileName;
          
        try {  
            // 使用Runtime来执行command,生成Process对象  
            Runtime runtime = Runtime.getRuntime();  
            process = runtime.exec(cmd);  
            // 取得命令结果的输出流  
            InputStream is = process.getInputStream();  
            // 用一个读输出流类去读  
            InputStreamReader isr = new InputStreamReader(is);  
            // 用缓冲器读行  
            BufferedReader br = new BufferedReader(isr);  
            String line = null;  
            while ((line = br.readLine()) != null) {  
                System.out.println(line);  
            }  
            //执行关闭操作
            is.close();  
            isr.close();  
            br.close();  
        } catch (IOException e) {  
            e.printStackTrace();  
        }  

相关文章:

  • 2021-10-07
  • 2022-12-23
  • 2022-01-20
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-16
  • 2022-12-23
  • 2021-12-06
  • 2019-12-25
  • 2022-01-28
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案