How to read a line from File in Java?
--------------------------------------
You can read a file line by line using both BufferedReader and Scanner in Java, but if you want to read a specific line in file then its not directly supported in Java. In Java 8, you can also use readAllLines() from File method for reading a file line by line in Java 8.
Solution
Advantages :
Disadvantages :
That's all about how to read a line in Java. You can either read whole file line by line using BufferedReader.readLine() method, or you can use Scanner.nextLine() method for same job. IF you want to read a specific line from file in Java then your only choice is using RandomAccessFile, which provides a file pointer to move around.
No comments:
Post a Comment
Feel free to comment, ask questions if you have any doubt.