如何对输入流进行检索
小弟有个需求执行一个外部程序,然后取得它的输出流作为我java程序的输入流
Process ps = Runtime.getRuntime().exec(cmd); String str = (loadStream(ps.getInputStream())); } private String loadStream(InputStream in) throws IOException { int ptr = 0; in = new BufferedInputStream(in); StringBuffer buffer = new StringBuffer(); while ((ptr = in.read()) != -1) { buffer.append((char) ptr); } return buffer.toString(); }