我在java中通过Process proc=Runtime.getRuntime().exec(cmd);   调用了其他程序,在这个进程中,有我想要的数据,但是我通过BufferedInputStream isb=new BufferedInputStream(proc.getInputStream());
FileOutputStream os=new FileOutputStream(savefile);
读出来的是0kb,不知道如何读出来其中有用的内容,请指教,谢谢了。

解决方案 »

  1.   


    Process p = Runtime.getRuntime().exec("ipconfig");
    BufferedInputStream is = new BufferedInputStream(p.getInputStream());
    byte[] buf = new byte[1024];
    int size = 0;
    while((size = is.read(buf)) != -1)
    System.out.println(new String(buf,0,size,"gbk"));
    is.close();
    没有问题,这样读取屏幕输出,你执行的是什么程序?
      

  2.   

    Process p = Runtime.getRuntime().exec("ipconfig");
    p.waitFor(); //需要加这行。不过,我这运行到waitFor()就不走了。
      

  3.   

    加waitfor干嘛..
    一般程序直接拿输出就行了你确定是把我的代码贴回去跑过了?
    你的代码哪?你运行的啥东西?你确定那程序有输出?
      

  4.   

    try {   
    String exeFullPathName="C:\\Program Files\\Macromedia\\FlashPaper 2\\FlashPrinter.exe";   
    String message="C:\\1.jpg";   
    String  saveFilePathName="C:\\Program Files\\Macromedia\\FlashPaper 2\\Interface";
    String print="flashpaperprinterui2";
    File savefile=new File(saveFilePathName,"1.swf");
    byte b[]=new byte[400];
    String []cmd={exeFullPathName,message};   
    Process proc=Runtime.getRuntime().exec(cmd);   

    if(proc.getErrorStream()!=null){
    BufferedInputStream isb=new BufferedInputStream(proc.getInputStream());
    FileOutputStream os=new FileOutputStream(savefile);
    int length=0;proc.waitFor();
    while((length=isb.read(b))!=-1){
    os.write(b,0,length);

    }

    isb.close();
    os.close();
    }
    } catch (IOException e) {   
    // TODO Auto-generated catch block   
    e.printStackTrace();   
    } catch (InterruptedException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }   
    不好意识 ,我没说清上边是源码。
      

  5.   

    这是GUI程序吧?
    InputStream只能拿到标准输出流,GUI肯定是做不到的