I need to read a file line by line using java.nio, but nio doesn’t have a method like readline() to read one, complete line at a time. What solutions are there?
I need to read a file line by line using java.nio , but nio
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
NIO is typically used to do either direct memory access or block mediated bulk data transfers. It does do other things, but other features have more to do with blocking and non-blocking data access.
As such, you might want to use NIO to grab the data quickly (or in a non-blocking manner); however, if you want to “read line by line” you would be better served by doing the line detection after NIO has read in the available data. This could easily be implemented by putting a “line reading” facade over the buffer that NIO just read.