You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: "In this article we will see how to read a file using the `BufferReader` class in Java."
7
+
description: "In this article we will see how to read a file using the `BufferedReader` class in Java."
8
8
9
9
---
10
10
11
-
In this article we will see how to read a file using the `BufferReader`class in Java.
11
+
In this article we will see how to read a file using the `BufferedReader`class in Java.
12
12
13
-
`BufferReader` class reads text from a character-input stream. Because of buffering characters it provides an efficient way to read characters, arrays, and lines.
13
+
`BufferedReader` class reads text from a character-input stream. Because of buffering characters it provides an efficient way to read characters, arrays, and lines.
14
14
15
-
`BufferReader` provides two important methods to read from the file. i.e `read()` and `readLine()`.
15
+
`BufferedReader` provides two important methods to read from the file. i.e `read()` and `readLine()`.
16
16
17
-
You can specify the bufferSize in `BufferReader`constructer. But as [motioned in the docs](https://docs.oracle.com/javase/8/docs/api/java/io/BufferedReader.html),
17
+
You can specify the bufferSize in `BufferedReader`constructer. But as [motioned in the docs](https://docs.oracle.com/javase/8/docs/api/java/io/BufferedReader.html),
18
18
>The default is large enough for most purposes.
19
19
20
-
## BufferReader`read()` method
20
+
## BufferedReader`read()` method
21
21
22
-
`BufferReader``read()` method reads a single character. IT returns the `int` representation of the char in range of 0 to 65535 (0x00-0xffff), or -1 if the end of the stream has been reached.
22
+
`BufferedReader``read()` method reads a single character. IT returns the `int` representation of the char in range of 0 to 65535 (0x00-0xffff), or -1 if the end of the stream has been reached.
23
23
24
24
We can cast `int` value returned by `read()` method to `char` to get the character value.
25
25
26
-
I have given an example to read a file character by character using the `read()` method of the `BufferReader` class
26
+
I have given an example to read a file character by character using the `read()` method of the `BufferedReader` class
27
27
```java
28
28
packagecom.coderolls;
29
29
30
30
importjava.io.*;
31
31
32
32
/**
33
33
* A java program to read file character by character using the
34
-
* read() method of the BufferReader Class.
34
+
* read() method of the BufferedReader Class.
35
35
*
36
36
* @author Gaurav Kukade at coderolls.com
37
37
*/
38
-
publicclassBufferReaderReadMethodExample {
38
+
publicclassBufferedReaderReadMethodExample {
39
39
40
40
publicstaticvoidmain(String[] args) {
41
41
@@ -65,9 +65,9 @@ Output
65
65
```
66
66
Welcome to coderolls.com!
67
67
```
68
-
See [this example on GitHub](https://github.com/coderolls/blogpost-coding-examples/blob/main/java-files-io/BufferReaderReadMethodExample.java).
68
+
See [this example on GitHub](https://github.com/coderolls/blogpost-coding-examples/blob/main/java-files-io/BufferedReaderReadMethodExample.java).
69
69
70
-
## BufferReader`readLine()` method
70
+
## BufferedReader`readLine()` method
71
71
As specified in the name, this method reads a line of text.
72
72
73
73
A line is considered to be terminated by any one of a line feed ('\n') or a carriage return ('\r').
@@ -83,12 +83,12 @@ import java.io.*;
83
83
84
84
/**
85
85
* A java program to read file line by line using the
86
-
* readLine() method of the BufferReader Class.
86
+
* readLine() method of the BufferedReader Class.
87
87
*
88
88
* @author Gaurav Kukade at coderolls.com
89
89
*
90
90
*/
91
-
publicclassBufferReaderReadLineMethodExample {
91
+
publicclassBufferedReaderReadLineMethodExample {
92
92
93
93
publicstaticvoidmain(String[] args) {
94
94
@@ -120,31 +120,33 @@ Welcome to coderolls.com!
120
120
121
121
Visit coderolls to read more coding tutorials!
122
122
```
123
-
See [this example on GitHub](https://github.com/coderolls/blogpost-coding-examples/blob/main/java-files-io/BufferReaderReadLineMethodExample.java).
123
+
See [this example on GitHub](https://github.com/coderolls/blogpost-coding-examples/blob/main/java-files-io/BufferedReaderReadLineMethodExample.java).
124
124
125
-
I have given below a combine example of the Java `BufferReader``read()` and `readLine()` method below
125
+
I have given below a combine example of the Java `BufferedReader``read()` and `readLine()` method below
0 commit comments