作者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
推 ogamenewbie:全讀入StringBuilder 轉String 用正規式抓ip 比對 12/10 01:44
→ GGsov:謝謝...卡在不知道怎讀怎判斷 Orz 12/10 21:08