我通过这段代码在while循环中取得了一些进展,这使我可以看到文本文件的所有行,但是我不断遇到重复出现的错误,称为java.io.nullException。
public static void main (String[] args){
Msg msg = c.element();
String line = msg.getLine();
Map<String, String> attributes = msg.getAttributes();
ArrayList<String> list = new ArrayList<String>();
try {
BufferedReader file = new BufferedReader(new FileReader("pro.txt"));
String line;
while ((line = file.readLine()) != null)
Pattern regex = Pattern.compile
("[^\\s\"]+|\"[^\"]*\"");
Matcher regexMatcher = regex.matcher(line);
while (regexMatcher.find()) {
String match = regexMatcher.group();
match = removeLeadingChar(match, "\"");
match = removeLeadingChar(match, "\'");
list.add(match);
}
System.out.print(line);