作者GGsov (GGsov)
看板java
标题[问题] 处理getInputStream的问题
时间Wed Dec 10 01:15:30 2008
import java.io.*;
class test {
public static void main(String[] args) {
try {
String cmd = "netstat -n";
String findIP="IP";
Process child = Runtime.getRuntime().exec(cmd);
// 获得输出
InputStream child_in = child.getInputStream();
int c;
while ((c = child_in.read()) != -1)
{
// System.out.println("kkk");
System.out.print((char)c);
//if((char)c==findIP)
}
child_in.close();
}
catch (IOException e)
{
System.err.println(e);
}
}
}
这个程式执行起来就跟在console mode打 netstat -n 一样
会显示出所有的连线情形
我想检查getInputStream 里面有没有某个IP
但是read()是一个byte一个byte的去读取
没办法用一个if(stringA==IP) 去做判断式
其他有关getInputStream的read实际上也还是一个byte这样读进来 只不过先暂存到array
想请问有没有什麽办法??
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 218.174.35.92
1F:推 ogamenewbie:全读入StringBuilder 转String 用正规式抓ip 比对 12/10 01:44
2F:→ GGsov:谢谢...卡在不知道怎读怎判断 Orz 12/10 21:08