Dan*_*icz 3 java lines bufferedreader
所以我正在阅读一个包含我在我的代码中早先写过的约会的文件.我想筛选文本文件并在某个日期查找约会并将它们添加到ArrayList中,但是当BufferedReader通过它时,它会跳过其他行...继承我的代码
public ArrayList<String> read(int checkDay, int checkMonth, int checkYear) {
ArrayList<String> events = new ArrayList<String>();
BufferedReader in = null;
String read;
try {
in = new BufferedReader(new FileReader("calendar.txt"));
while ((read = in.readLine()) != null) {
read = in.readLine();
String[] split = read.split(",");
System.out.println(read);
if (split[1].equals(Integer.toString(checkDay)) && split[2].equals(Integer.toString(checkMonth)) && split[3].equals(Integer.toString(checkYear))) {
events.add(split[0] + " : " + split[1] + "/" + split[2] + "/" + split[3]);
}
}
} catch (IOException e) {
System.out.println("There was a problem: " + e);
e.printStackTrace();
} finally {
try {
in.close();
} catch (Exception e) {
}
}
return events;
}
Run Code Online (Sandbox Code Playgroud)
你正在读两行......
while ((read = in.readLine()) != null) { // here
read = in.readLine(); // and here
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5663 次 |
| 最近记录: |