What is the best way to read a text file two lines at a time in Java?
问题 BufferedReader in; String line; while ((line = in.readLine() != null) { processor.doStuffWith(line); } This is how I would process a file line-by-line. In this case, however, I want to send two lines of text to the processor in every iteration. (The text file I'm processing essentially stores one record on two lines, so I'm sending a single record to the processor each time.) What's the best way of doing this in Java? 回答1: Why not just read two lines? BufferedReader in; String line; while (