Java Code to Read Text File

import java.io.*;
class ReadFile
{
public static void main(String args[])
{
try{
FileInputStream fstream = new FileInputStream("C:\\java\\demo\\file.txt");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String Data;
while ((Data = br.readLine()) != null)   {
System.out.println (Data);
}
in.close();
}
catch (Exception e)
{
System.err.println("Error: " + e.getMessage());
}
}
}

No comments:

Post a Comment

My Profile