Skip to content

Correct bufferedReader Examples #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,24 @@

import java.io.*;

public class BufferReaderExanple {
public class BufferedReaderExanple {

public static void main(String[] args) {
BufferedReader bufferedReader = null;
try {
bufferedReader = new BufferedReader(new FileReader("F:\\sample-text.txt"));
System.out.println("Read file using read() method: ");
readFileCharacterByCharacter(bufferedReader);

bufferedReader = new BufferedReader(new FileReader("F:\\sample-text-two-lines.txt"));
System.out.println("\n\nRead file using readLine() method: ");
readFileLineByLine(bufferedReader);

} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

readFileCharacterByCharacter(bufferedReader);

readFileLineByLine(bufferedReader);


try {
bufferedReader.close();
} catch (IOException e) {
Expand All @@ -26,7 +28,7 @@ public static void main(String[] args) {
}

/**
* A method to read file content character by character using the BufferReader
* A method to read file content character by character using the BufferedReader
* read() method
*
* @param bufferedReader
Expand All @@ -44,7 +46,7 @@ public static void readFileCharacterByCharacter(BufferedReader bufferedReader) {
}

/**
* A method to read file content line by line using the BufferReader
* A method to read file content line by line using the BufferedReader
* readLine() method
*
* @param bufferedReader
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@

/**
* A java program to read file line by line using the
* readLine() method of the BufferReader Class.
* readLine() method of the BufferedReader Class.
*
* @author Gaurav Kukade at coderolls.com
*
*/
public class BufferReaderReadLineMethodExample {
public class BufferedReaderReadLineMethodExample {

public static void main(String[] args) {

BufferedReader bufferedReader = null;
try {
bufferedReader = new BufferedReader(new FileReader("F:\\sample-text.txt"));
bufferedReader = new BufferedReader(new FileReader("F:\\sample-text-two-lines.txt"));

String line;
//read each line using readLine() method and print it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

/**
* A java program to read file character by character using the
* read() method of the BufferReader Class.
* read() method of the BufferedReader Class.
*
* @author Gaurav Kukade at coderolls.com
*
*/
public class BufferReaderReadMethodExample {
public class BufferedReaderReadMethodExample {

public static void main(String[] args) {

Expand Down