服务热线:13616026886

技术文档 欢迎使用技术文档,我们为你提供从新手到专业开发者的所有资源,你也可以通过它日益精进

位置:首页 > 技术文档 > JAVA > 新手入门 > 基础入门 > 查看文档

java核心代码例程之:processdemo.java


import java.io.*;


/**
 * demonstrates how to run a program and read it"s output
 ***/
public class processdemo
{
    public static void main(string args[]) throws exception
    {
        process process = runtime.getruntime().exec("ls");
        inputstream standardoutput = process.getinputstream(),
                    standarderror  = process.geterrorstream();
                   
        int c;
        system.out.println("
[ standard output ]");
        while ((c = standardoutput.read()) != -1)
           system.out.print((char)c);
           
        system.out.println("
[ standard error ]");
        while ((c = standarderror.read()) != -1)
           system.out.print((char)c);
           
        standardoutput.close();
        standarderror.close();
    }
}

扫描关注微信公众号