/* * FileRead.java * * Created on January 10, 2011, 4:36 PM * * To change this template, choose Tools | Template Manager * and open the template in the editor. */ package file; import java.io.BufferedReader; import java.io.DataInputStream; import java.io.FileInputStream; import java.io.InputStreamReader; /** * * @author ocamposm */ public class FileRead { /** Creates a new instance of FileRead */ public FileRead() { } public static void main(String args[]){ try{ //Open the file FileInputStream fstream = new FileInputStream("textfile.txt"); //Get the object of DataInputStream DataInputStream in =new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine; //Read file Line by Line while ((strLine=br.readLine())!=null) { //Print the content on the console System.out.println(strLine); } //Close the input stream in.close(); }catch (Exception e){//Catch exception if any System.err.println("Error:" + e.getMessage()); } } }