BufferedReader is skipping every other line when reading my file in java

后端 未结 3 1665
花落未央
花落未央 2020-11-29 13:38

So Im working of reading a file containing appointments that I wrote to earlier in my code. I want to sift through the text file and find appointments on a certain date and

3条回答
  •  半阙折子戏
    2020-11-29 14:06

    pl try this

    you r using "read = in.readLine())" two times in while loop that why it is skiping the lomes

    public ArrayList read(int checkDay, int checkMonth, int checkYear) {
            ArrayList events = new ArrayList();
            BufferedReader in = null;
            String read;
            try {
                in = new BufferedReader(new FileReader("calendar.txt"));
                while ((read = in.readLine()) != null) {
    
                    String[] split = read.split(",");
                    System.out.println(read);
    
                    if (split[0].equals(Integer.toString(checkDay)) && split[1].equals(Integer.toString(checkMonth)) && split[2].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;
    

提交回复
热议问题