当前位置: 代码迷 >> Eclipse >> 求大神棒棒忙!该如何解决
  详细解决方案

求大神棒棒忙!该如何解决

热度:6   发布时间:2016-04-23 00:23:30.0
求大神棒棒忙!!

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


public class TEmailSpider {

public static void main(String[] args) {
try {
BufferedReader br = new BufferedReader(new FileReader("G:\\java_programs\\网页\\【阅经典庆十一】你的生活照够装逼吗?!_阅经吧_百度贴吧.html"));
String line = "";
while((line=br.readLine()) != null) {
parse(line);
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

private static void parse(String line) {

Pattern p = Pattern.compile("^id\\s\\=\\s\\w");
Matcher m = p.matcher(line);
while(m.find()) {
System.out.println(m.group());
}
}

}



这个程序执行的错误是这样的:

at java.io.FileInputStream.<init>(FileInputStream.java:146)
at java.io.FileInputStream.<init>(FileInputStream.java:101)
at java.io.FileReader.<init>(FileReader.java:58)
at TEmailSpider.main(TEmailSpider.java:16)


是不是要导入什么啊,怎么导入?
------解决思路----------------------
程序应该没问题,G盘下没有文件,或者那个文件的格式特殊造成的

可以运行的版本如下:

package topics_390899922;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class TEmailSpider {

    public static void main(String[] args) {
        try {
            BufferedReader br = new BufferedReader(new FileReader(
                    "C:\\test.txt"));
            String line = "";
            while ((line = br.readLine()) != null) {
                parse(line);
            }
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    private static void parse(String line) {

        Pattern p = Pattern.compile("^id\\s\\=\\s\\w");
        Matcher m = p.matcher(line);
        while (m.find()) {
            System.out.println(m.group());
        }
    }

}


输出:
id = 1
id = 2
id = 3


运行之前,请在C盘根目录下放置好【test.txt】文件
test.txt文件的内容如下:
id = 1
id = 2
id = 3
  相关解决方案