用下面的程序为什么判断不了以下两行的区别,这两行是standered方法处理后的两个tmp文件里的,我执行后diff文件是空的
tcp        0      0  *.22                   *.*                    LISTEN
tcp        0      0  *.21                   *.*                    LISTEN
import java.io.*;
import java.util.*;
public class fenxi {
private static String s1 = null;
private static String s2 = null;
public static void main(String[] args) {
File f = new File("fenxi.conf");
try {
FileReader read = new FileReader (f);
BufferedReader readpath = new BufferedReader(read);
String path;
while ((path = readpath.readLine())!=null)
{
File getpath = new File(path);
String[] pathfile = getpath.list();
File cf = new File(path,pathfile[0]+"_is_stander");
RandomAccessFile o = new RandomAccessFile (cf,"rw");
fenxi ck = new fenxi();
for(int i=0;i<pathfile.length;i++)
{
s2 = pathfile[i];
ck.standered(s2,path);
}
for(int i=1;i<pathfile.length;i++){
ck.comp(pathfile[0],pathfile[i],path);
o.writeByte(i);
}
}
    }catch (IOException e)
{
System.out.println(e);
} }
public void standered(String f1,String p){
File fcomp1 = new File(p,f1);
// File outf = new File(p,f1+"std");
File oute = new File(p,f1+"err");
File outo = new File(p,f1+"tmp");
int len = f1.length();
try {
FileReader read = new FileReader (fcomp1);
BufferedReader readpath = new BufferedReader(read);
// RandomAccessFile out1 = new RandomAccessFile (outf,"rw");
RandomAccessFile out2 = new RandomAccessFile (oute,"rw");
RandomAccessFile out3 = new RandomAccessFile (outo,"rw");
String Proto=null;
String Recv = null;
String Send = null;
String local =null;
String remot = null;
String stat = null;
String temp = null;
String local1 = null;
while ((temp = readpath.readLine())!=null){
if(!(temp.startsWith("tcp")))
  continue;
StringTokenizer fen = new StringTokenizer(temp);
  while(fen.hasMoreTokens()){
  Proto= fen.nextToken();
  Recv = fen.nextToken();
  Send = fen.nextToken();
  local= fen.nextToken();
  remot = fen.nextToken();
  stat = fen.nextToken();
  }
  if(stat.equals("LISTEN")){
   String regex = "\\D\56[1-9]{1,}";
  if(!(local.matches(regex))){
  continue;
  }
  long filepoint = out3.length();
  out3.seek(filepoint);
  out3.writeBytes(temp+"\n");
  }
  else if(stat.equals("ESTABLISHED")){
//   String regex1 = "\\d{1,}\56\\d{1,}\56\\d{1,}\56\\d{1,}";
  String remot1 = remot.substring(0, len);
//   temp.replaceAll(regex1, remot1);
  if(remot1.equals(f1))
  continue;
  if(remot.startsWith("127.0.0.1"))
  continue;
  long filepoint = out3.length();
  out3.seek(filepoint);
  out3.writeBytes(temp+"\n");
  }
  else {
  long filepoint = out2.length();
  out2.seek(filepoint);
  out2.writeBytes(temp+"\n");}
  
  
}
}catch (IOException e)
{
System.out.println(e);
}

}
public void comp(String s1,String s2,String p){
int len = s1.length()-1;
int len2 = s2.length()-1;
File cf1 = new File(p,s1+"tmp");
File cf2 = new File(p,s2+"tmp");
// File cfs = new File(p,s2+"same");
File cfd = new File(p,s2+"diff");
try {
FileReader read1 = new FileReader (cf1);
FileReader read2 = new FileReader (cf2);
BufferedReader readpath1 = new BufferedReader(read1);
BufferedReader readpath2 = new BufferedReader(read2);
// RandomAccessFile out1 = new RandomAccessFile (cfs,"rw");
RandomAccessFile out2 = new RandomAccessFile (cfd,"rw");
String Proto=null;
String Recv = null;
String Send = null;
String local =null;
String remot = null;
String stat = null;
String temp = null;
String local1 = null;
String Proto2=null;
String Recv2 = null;
String Send2 = null;
String local2 =null;
String remot2 = null;
String stat2 = null;
String temp2 = null;
String local12 = null;
long filepoint;
while ((temp = readpath1.readLine())!=null){
StringTokenizer fen = new StringTokenizer(temp," ");
  while(fen.hasMoreTokens()){
  Proto= fen.nextToken().trim();
  Recv = fen.nextToken().trim();
  Send = fen.nextToken().trim();
  local= fen.nextToken().trim();
  remot = fen.nextToken().trim();
  stat = fen.nextToken().trim();
  }
while ((temp2 = readpath2.readLine())!=null){
StringTokenizer fen2 = new StringTokenizer(temp2," ");
  while(fen2.hasMoreTokens()){
  Proto2= fen2.nextToken().trim();
  Recv2 = fen2.nextToken().trim();
  Send2 = fen2.nextToken().trim();
  local2= fen2.nextToken().trim();
  remot2 = fen2.nextToken().trim();
  stat2 = fen2.nextToken().trim();
  }
if(stat.equals("ESTABLISHED")){
remot=remot.substring(0, len);
remot2=remot2.substring(0, len);
if(temp.indexOf(remot2)!=-1){
// filepoint = out1.length();
// out1.seek(filepoint);
// out1.writeBytes(temp+"\n");}
filepoint = cfd.length();
out2.seek(filepoint);
out2.writeBytes(temp+"\n");
//break;
}
else if(stat.equals("LISTEN")){
if(temp.indexOf(stat2)!=-1){
// System.out.println(local);
// System.out.println(local2);
// filepoint = cfs.length();
// out1.seek(filepoint);
// out1.writeBytes(temp+"\n");
filepoint = cfd.length();
out2.seek(filepoint);
out2.writeBytes(temp+"\n");
//break;
}

}
}
}
}
}catch (IOException e)
{
System.out.println(e);
}

}
}

解决方案 »

  1.   

    说实话  看起来超级累  不过还是坚持的看了一下  建议楼主还是这样放到代码格式块里
    public void comp(String s1,String s2,String p)
    对比的方法
    for(int i=1;i<pathfile.length;i++){
    ck.comp(pathfile[0],pathfile[i],path);
    o.writeByte(i);
    }
    这里是调用你的这个方法显然是要进行对比的方法,可是方法没有返回值,而且没有对全局变量赋值,
    不知道楼主写这个方法的意义是什么?