How do you read file line by line?

How do you read file line by line?

Postby Kishan » Fri Feb 01, 2013 5:40 am

How do you read file line by line?
Kishan
 
Posts: 191
Joined: Tue Jan 29, 2013 4:21 am

Re: How do you read file line by line?

Postby Kishan » Thu Feb 07, 2013 6:06 am

Code: Select all
package javatrng.examples.io;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;


public class BufferedExample {

   public static void main(String[] args) {
      BufferedReader is = null;
      
      try {
         is = new BufferedReader(new FileReader("c:\\work\\io\\temp.txt"));
         String line = null;
         while((line = is.readLine()) != null) {
            System.out.println(line);
         }
      } catch (Exception e) {
         e.printStackTrace();
      } finally {
         if(is != null) {
            try {
               is.close();
            } catch (IOException e) {
               e.printStackTrace();
            }
         }
      }
   }
}
Kishan
 
Posts: 191
Joined: Tue Jan 29, 2013 4:21 am


Return to Core Java

Who is online

Users browsing this forum: No registered users and 1 guest

cron