[問題] 處理getInputStream的問題

看板java作者 (GGsov)時間17年前 (2008/12/10 01:15), 編輯推噓1(101)
留言2則, 2人參與, 最新討論串1/1
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

12/10 01:44, , 1F
全讀入StringBuilder 轉String 用正規式抓ip 比對
12/10 01:44, 1F

12/10 21:08, , 2F
謝謝...卡在不知道怎讀怎判斷 Orz
12/10 21:08, 2F
文章代碼(AID): #19FgUpnD (java)