Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java SE 综合讨论区  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 Re:关于读取整个文件字符串的问题,急,在线等 [Re:mrs_cadbary]
mrs_cadbary





发贴: 12
积分: 0
于 2005-12-03 19:20 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
上面的循环挺有用,不过我要实现的是从一个名为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
..


why edited on 2005-12-04 05:43


菜鸟请教,基本程序调试不通,急急急急急急!!!

话题树型展开
人气 标题 作者 字数 发贴时间
7617 关于读取整个文件字符串的问题,急,在线等 mrs_cadbary 95 2005-12-02 08:55
5863 Re:关于读取整个文件字符串的问题,急,在线等 abc__abc1 15 2005-12-02 09:19
8410 Re:关于读取整个文件字符串的问题,急,在线等 mrs_cadbary 250 2005-12-02 09:36
5717 Re:关于读取整个文件字符串的问题,急,在线等 mrs_cadbary 38 2005-12-02 09:41
5821 Re:关于读取整个文件字符串的问题,急,在线等 abc__abc1 20 2005-12-02 09:50
5912 Re:关于读取整个文件字符串的问题,急,在线等 abc__abc1 693 2005-12-02 10:05
5999 Re:关于读取整个文件字符串的问题,急,在线等 mrs_cadbary 6596 2005-12-03 19:20

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923