Created
March 4, 2010 18:28
-
-
Save tmountain/321989 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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