Skip to content

Instantly share code, notes, and snippets.

@tmountain
Created March 4, 2010 18:28
Show Gist options
  • Save tmountain/321989 to your computer and use it in GitHub Desktop.
Save tmountain/321989 to your computer and use it in GitHub Desktop.
import java.io.*;
class FileRead {
public void readEachLine(String filename) {
try {
// Open the file that is the first
// command line parameter
FileInputStream fstream = new FileInputStream(filename);
// 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) {
// do something with the line ...
System.out.println(strLine);
}
//Close the input stream
in.close();
} catch (Exception e) { }
}
public static void main(String[] args) {
FileRead fileReader = new FileRead();
fileReader.readEachLine("/tmp/foo.txt");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment