代码中的看我的解释:
public static void main (String[] args) {
int db2Name;
String fname = "c:\\1.txt";
File f = new File(fname);
try {
FileReader fr = new FileReader(f);
BufferedReader br = new BufferedReader(fr);
//String s = br.readLine();//这里你获得了文件中的第一行,
//而你的2.txt中的第一行为空,所以后面while (s!=null)个循环就不执行了,
int i=0;
while(true){
i++;
s=br.readLine();
if(s!=null) break;
if(i>=100) {
System.out.println("文件为空,");//我这里自认为文件前100行没内容文件就为空
break;
}
}
//其实你后面也有此错误,自己安我的这个解决
Pattern p = Pattern.compile("\\W(s.([0-9])*?)\\W");
Matcher m = p.matcher(s);
System.out.println("b");
while (s!=null){
while (m.find()) {
System.out.println(m.group(1).substring(1, 8));
db2Name=Integer.parseInt(m.group(1).substring(1, 8));
} s= br.readLine();
}
br.close();// 关闭缓冲读入流及文件读入流的连接.
System.out.println("a");
} catch (FileNotFoundException e1) {
System.err.println("File not found: " + fname);
} catch (IOException e2) {
e2.printStackTrace();
}
}
后面几句没看懂意思。。汗。。