我在java中通过Process proc=Runtime.getRuntime().exec(cmd); 调用了其他程序,在这个进程中,有我想要的数据,但是我通过BufferedInputStream isb=new BufferedInputStream(proc.getInputStream());
FileOutputStream os=new FileOutputStream(savefile);
读出来的是0kb,不知道如何读出来其中有用的内容,请指教,谢谢了。
FileOutputStream os=new FileOutputStream(savefile);
读出来的是0kb,不知道如何读出来其中有用的内容,请指教,谢谢了。
解决方案 »
- 探讨生成excel的方法
- 请教高手此问题解决方法
- jboss 下部署ssh工程报 java.lang.ClassCastException: com.sun.faces.config.WebConfiguration
- java连sql
- 关于spring的<spring:bind>问题!!!
- 公司强制要求直接学spring,可以吗?
- 问个关于hibernate连接超时的问题
- 想把Web Service应用到毕业设计中,希望高手多给些建议
- 这样的系统您开价多少?
- JBUILDER8和JBOSS3.04(与TOMCAT4.1合成)能够实现WEB SERVICE功能的开发吗?
- 物流管理系统中路线的问题
- 急求!不能设置共享文件夹,RPC服务不可用
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();
没有问题,这样读取屏幕输出,你执行的是什么程序?
p.waitFor(); //需要加这行。不过,我这运行到waitFor()就不走了。
一般程序直接拿输出就行了你确定是把我的代码贴回去跑过了?
你的代码哪?你运行的啥东西?你确定那程序有输出?
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();
}
不好意识 ,我没说清上边是源码。
InputStream只能拿到标准输出流,GUI肯定是做不到的