上面的循环挺有用,不过我要实现的是从一个名为printname的文件中查找ip地址为192.168.0.120的机器上程序运行的信息,我的java程序代码如下
import java.io.*;
import java.lang.*;
class Printname2
{ public static void main(String args[])throws IOException{ //@1 @2
BufferedReader p=new BufferedReader(new InputStreamReader(new FileInputStream("d:\\Jfiles\\printname2.txt"))); //读取文档
String a=p.readLine();
String[] aa = a.split("\\..",0); //以“#”为分隔符将文档分割为 b[]
//File print=new File("d:\\Jfiles\\print.txt"); //输出到文件
for (int i = 0 ; i <aa.length ; i++ )
{ String[] b=aa[i].split(" ",0); //以空格为分隔符将b[i]分割 @3
String string1=b[5];
String string2="submitted";
if(string1.equals(string2)==true) //当b[i]中包含submitted字段时执行以下程序
{ String[] c=b[8].split(":",0); //@4
String string3=c[0];
String string4="<192.168.0.120";
if (string3.equals(string4)==true) //当b[i]中包含要求的ip地址时执行以下程序
{String string5=b[1]; //@5
System.out.println(aa[i]); //输出此程序的请求信息
//PrintStream p1=new PrintStream(new FileOutputStream(print),true);
//p1.println(aa[i]);
for (int j = i+1 ; j <aa.length ; j++ )
{String[] d=aa[j].split(" ",0); //@6
String string6=d[1];
if (string6.equals(string5)==true) //以b[i]中第二字符串即进程号为筛选以下信息的关键字
{String string7=d[5]; //@7
String string8="executing";
if(string7.equals(string8)==true)
{System.out.println(aa[j]); //输出此程序的收到信息 @8
//PrintStream p2=new PrintStream(new FileOutputStream(print),true);
//p2.println(aa[j]);
for (int n = j+1 ; n <aa.length ; n++ )
{String[] e=aa[n].split(" ",0); //@9
String string9=e[1];
if (string9.equals(string5)==true)
{System.out.println(aa[n]); //输出此程序的执行信息 @10
//PrintStream p3=new PrintStream(new FileOutputStream(print),true);
//p3.println(aa[n]);
continue;
} //@10
} //@9
} //@8
} //@7
// else return;
} //@6
} //@5
} //@4
// else return;
} //@3
} //@2
}
如果我用readline的循环该怎么返回ip地址呢
printname.txt的内容如下(包含换行符)
000 (277.000.000) 11/04 20:51:40 Job submitted from host: <192.168.0.121:1027>
..
001 (277.000.000) 11/04 20:51:44 Job executing on host: <192.168.0.121:1026>
..
005 (277.000.000) 11/04 20:51:45 Job terminated.
(1) Normal termination (return value 0)
Usr 0 00:00:00, Sys 0 00:00:00 - Run Remote Usage
Usr 0 00:00:00, Sys 0 00:00:00 - Run Local Usage
Usr 0 00:00:00, Sys 0 00:00:00 - Total Remote Usage
Usr 0 00:00:00, Sys 0 00:00:00 - Total Local Usage
203 - Run Bytes Sent By Job
96 - Run Bytes Received By Job
203 - Total Bytes Sent By Job
96 - Total Bytes Received By Job
..
000 (278.000.000) 11/04 20:53:12 Job submitted from host: <192.168.0.120:1027>
..
000 (279.000.000) 11/04 20:53:12 Job submitted from host: <192.168.0.120:1027>
..
000 (280.000.000) 11/04 20:53:13 Job submitted from host: <192.168.0.121:1027>
..
001 (278.000.000) 11/04 20:53:16 Job executing on host: <192.168.0.120:1026>
..
005 (278.000.000) 11/04 20:53:16 Job terminated.
(1) Normal termination (return value 0)
Usr 0 00:00:00, Sys 0 00:00:00 - Run Remote Usage
Usr 0 00:00:00, Sys 0 00:00:00 - Run Local Usage
Usr 0 00:00:00, Sys 0 00:00:00 - Total Remote Usage
Usr 0 00:00:00, Sys 0 00:00:00 - Total Local Usage
203 - Run Bytes Sent By Job
96 - Run Bytes Received By Job
203 - Total Bytes Sent By Job
96 - Total Bytes Received By Job
..
001 (279.000.000) 11/04 20:53:19 Job executing on host: <192.168.0.120:1026>
..
005 (279.000.000) 11/04 20:53:19 Job terminated.
(1) Normal termination (return value 0)
Usr 0 00:00:00, Sys 0 00:00:00 - Run Remote Usage
Usr 0 00:00:00, Sys 0 00:00:00 - Run Local Usage
Usr 0 00:00:00, Sys 0 00:00:00 - Total Remote Usage
Usr 0 00:00:00, Sys 0 00:00:00 - Total Local Usage
203 - Run Bytes Sent By Job
96 - Run Bytes Received By Job
203 - Total Bytes Sent By Job
96 - Total Bytes Received By Job
..
001 (280.000.000) 11/04 20:53:21 Job executing on host: <192.168.0.121:1026>
..
005 (280.000.000) 11/04 20:53:21 Job terminated.
(1) Normal termination (return value 0)
Usr 0 00:00:00, Sys 0 00:00:00 - Run Remote Usage
Usr 0 00:00:00, Sys 0 00:00:00 - Run Local Usage
Usr 0 00:00:00, Sys 0 00:00:00 - Total Remote Usage
Usr 0 00:00:00, Sys 0 00:00:00 - Total Local Usage
203 - Run Bytes Sent By Job
96 - Run Bytes Received By Job
203 - Total Bytes Sent By Job
96 - Total Bytes Received By Job
..