Thursday, November 15, 2012
Java Program to Read a File Data Line By Line
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.InputStreamReader;
class ReadFileExample
{
public static void main(String args[])
{
try{
// Open the file that is the first
FileInputStream fstream = new FileInputStream("C:/MyWorkSpace/Temp/src/Fileall.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());
}
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment