Problem : How you can read line by line from a text file?
Solution : java.io.BufferedReader class has a readLine() method which stored data from java.io.FileReader class read() method and read file line by line. Below is sample program. Program :Step 1 - CodingCreate a text file c:/sunilos/ReadLine.java and copy below contents.import java.io.BufferedReader; import java.io.FileReader; /** * A program to read file line by line. */ public class ReadLine { public static void main(String[] args) throws Exception{ //FileReader reads streams of characters FileReader reader = new FileReader("c:/sunilos/sunilos.txt"); //BufferedRead read text from a character-input stream. BufferedReader bufferedReader = new BufferedReader(reader); String line = bufferedReader.readLine(); while(line!=null){ System.out.println(line); line = bufferedReader.readLine(); } reader.close(); } } Step 2 - Deployment
Step 3 - Testing
OutputA software services and corporate training company specializing in DistributedObject Oriented and Client Server Technologies with a strong background of J2EE. FAQWhat is BufferedReader?
Most Interesting methods in BufferedReader?
<<Previous | Next>> |