我正在使用缓冲读取器读取一些包含信息行的文件。 一些较长的文本行超过一行,因此缓冲区以新行查看它们。 每行以';'
符号结尾。 所以我想知道是否有一种方法可以使缓冲读取器读取一行直到达到';'
然后将整行作为字符串返回。 这里是迄今为止我正在使用的缓冲读取器。
String currentLine;
while((currentLine = reader.readLine()) != null) {
// trim newline when comparing with lineToRemove
String[] line = currentLine.split(" ");
String fir = line[1];
String las = line[2];
for(int c = 0; c < players.size(); c++){
if(players.get(c).getFirst().equals(fir) && players.get(c).getLast().equals(las) ){
System.out.println(fir + " " + las);
String text2 = currentLine.replaceAll("[.*?]", ".150");
writer.write(text2 + System.getProperty("line.separator"));
}
}
}
BufferedReader.readLine
。 - Jon SkeetScanner
并将分隔符设置为;
。我相信有一些相关的教程“在外面”。 - Tom