要比较一个文件里的2个字符串,如下:
Tue Jun 03 11:23:06 CST 2008> 扫描结果:2e6c5e153590af08e61eaba0643325ed
Tue Jun 03 13:59:09 CST 2008> 扫描结果:2e6c5e153590af08e61eaba0643325ed
具体的说就是比较后面的2个字符串,应该如何实现啊 ,首先是如何把他们提取出来,然后再比较,请教高人解答!

解决方案 »

  1.   


    String str1 = "";
    String str2 = "";好像只能定义两个变量,然后把文件中的所有数据一行一行的读出到str1,str2中!最后比较str1, str2;
      

  2.   

    提供下方法..你自己来..首先 readline..把这一行读入..然后lastIndexOf(":") 
              返回最后一次出现的指定字符在此字符串中的索引。然后 substring(int beginIndex) 
              返回一个新的字符串,它是此字符串的一个子字符串。  就把这个字符串截取下来了..第二个同上..两个都出来了..  
    比较就看你自己得了.
      

  3.   


    public class Main {    public static void main(String[] args) {
            String s1 = "Tue Jun 03 11:23:06 CST 2008> 扫描结果:2e6c5e153590af08e61eaba0643325ed";
            String s2 = "Tue Jun 03 13:59:09 CST 2008> 扫描结果:2e6c5e153590af08e61eaba0643325ed";
            String regex = ".*?扫描结果:((\\p{XDigit})+)";
            Pattern p = Pattern.compile(regex);
            Matcher m1 = p.matcher(s1);
            Matcher m2 = p.matcher(s2);
            if (m1.find() && m2.find()) {
                //输出小于0,说明 <,大于零 > 。否则=
                System.out.println(m1.group(1).compareTo(m2.group(1)));
            }
        }
    }
      

  4.   


    public class Main {    static List<String> list = new ArrayList<String>();    public static void main(String[] args) throws IOException {        BufferedReader br = new BufferedReader(new FileReader(new File("File path")));
            String line = null;
            while ((line = br.readLine()) != null) {
                list.add(toHexString(line));
            }
            Collections.sort(list);
            System.out.println(list);    }    public static String toHexString(String s) {        String regex = ".*?执行结果:((\\p{XDigit})+)";
            Pattern p = Pattern.compile(regex);
            Matcher m = p.matcher(s);
            if (m.find()) {
                return m.group(1);
            }
            return "";
        }
    }