adsense


Showing posts with label JAVA EXAMPLES READ A FILE. Show all posts
Showing posts with label JAVA EXAMPLES READ A FILE. Show all posts

Tuesday, 27 October 2015

JAVA EXAMPLES READ A FILE PAGE PAGE 100

COMPUTER LANGUAGES HTML,C,C++.JAVA,.NET AND MULTIMEDIA basics and programs click home button



JAVA EXAMPLES READ A FILE






Java Examples - Read a file


Problem Description:
How to read a file?
Solution:
This example shows how to read a file using readLine method of BufferedReader class.
import java.io.*;

public class Main {
   public static void main(String[] args)  {
      try {
         BufferedReader in = new BufferedReader
         (new FileReader("c:\\filename"));
         String str;
         while ((str = in.readLine()) != null) {
            System.out.println(str);
         }
         System.out.println(str);
         }
         catch (IOException e) {
         }
      }
   }
}
Result:
The above code sample will produce the following result.
aString