Created
November 6, 2016 03:21
-
-
Save NickersF/12fa1b8fca02451da3b2e2d25d22290e to your computer and use it in GitHub Desktop.
Getting a basic buffered reader up and running
This file contains 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.BufferedReader; | |
import java.io.FileNotFoundException; | |
import java.io.FileReader; | |
import java.io.IOException; | |
/** | |
* Created by nickersf on 11/2/2016. | |
* | |
* A class for testing the buffered reader object in Java | |
*/ | |
public class SampleBufferedReader { | |
private BufferedReader inputStream; // BufferedReader object to read file contents | |
// Constructor instantiates a new BufferedReader for use | |
public SampleBufferedReader(String dataFilename) { | |
try { | |
inputStream = new BufferedReader(new FileReader(dataFilename)); | |
} | |
catch (FileNotFoundException e) { | |
System.out.println("Exception thrown: " + e); | |
} | |
} | |
// Prints all the data in the file line by line | |
public void printDataFile() { | |
try { | |
while (inputStream.readLine() != null){ | |
System.out.println(inputStream.readLine()); | |
} | |
// Close the stream object | |
inputStream.close(); | |
} | |
catch (IOException e1) { | |
System.out.println("Exception thrown: " + e1); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment