public class FileParser {
private String filename = "mydata.txt";
private Pattern pattern = Pattern.compile("\\D\\D\\d+");
private Scanner reader;
public FileParser() throws FileNotFoundException{
reader = new Scanner(new File(filename));
}
public boolean hasMoreData(){
return reader.hasNext(pattern);
}
public String[] getNextData(){
return pattern.split(reader.next(pattern));
}
public void close(){
reader.close();
}
}
所以这是我的代码。我试图取出一个由 2 个字母和一个数字组成的模式。为什么我从 getNextData() 函数中什么也得不到/空数组?