使C fork代码适应Java程序

使C fork代码适应Java程序,第1张

使C fork代码适应Java程序

在Java中,可能看起来像-

public static void main(String[] args) {    try {        Process p = Runtime.getRuntime().exec("/bin/ls");        final InputStream is = p.getInputStream();        Thread t = new Thread(new Runnable() { public void run() {     InputStreamReader isr = new InputStreamReader(is);     int ch;     try {         while ((ch = isr.read()) != -1) {  System.out.print((char) ch);         }     } catch (IOException e) {         e.printStackTrace();     } }        });        t.start();        p.waitFor();        t.join();        System.out.println("Child Complete");    } catch (Exception e) {        e.printStackTrace();    }}


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5507095.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-13
下一篇 2022-12-13

发表评论

登录后才能评论

评论列表(0条)

保存