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
-
In this article we will see how to read a file using the `BufferReader`class in Java.
10
+
In this article we will see how to read a file using the `BufferedReader`class in Java.
11
11
12
-
`BufferReader` class reads text from a character-input stream. Because of buffering characters it provides an efficient way to read characters, arrays, and lines.
12
+
`BufferedReader` class reads text from a character-input stream. Because of buffering characters it provides an efficient way to read characters, arrays, and lines.
13
13
14
-
`BufferReader` provides two important methods to read from the file. i.e `read()` and `readLine()`.
14
+
`BufferedReader` provides two important methods to read from the file. i.e `read()` and `readLine()`.
15
15
16
-
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),
16
+
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),
17
17
>The default is large enough for most purposes.
18
18
19
-
## BufferReader`read()` method
19
+
## BufferedReader`read()` method
20
20
21
-
`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.
21
+
`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.
22
22
23
23
We can cast `int` value returned by `read()` method to `char` to get the character value.
24
24
25
-
I have given an example to read a file character by character using the `read()` method of the `BufferReader` class
25
+
I have given an example to read a file character by character using the `read()` method of the `BufferedReader` class
26
26
```java
27
27
packagecom.coderolls;
28
28
29
29
importjava.io.*;
30
30
31
31
/**
32
32
* A java program to read file character by character using the
33
-
* read() method of the BufferReader Class.
33
+
* read() method of the BufferedReader Class.
34
34
*
35
35
* @author Gaurav Kukade at coderolls.com
36
36
*/
37
-
publicclassBufferReaderReadMethodExample {
37
+
publicclassBufferedReaderReadMethodExample {
38
38
39
39
publicstaticvoidmain(String[] args) {
40
40
@@ -64,9 +64,9 @@ Output
64
64
```
65
65
Welcome to coderolls.com!
66
66
```
67
-
See [this example on GitHub](https://github.com/coderolls/blogpost-coding-examples/blob/main/java-files-io/BufferReaderReadMethodExample.java).
67
+
See [this example on GitHub](https://github.com/coderolls/blogpost-coding-examples/blob/main/java-files-io/BufferedReaderReadMethodExample.java).
68
68
69
-
## BufferReader`readLine()` method
69
+
## BufferedReader`readLine()` method
70
70
As specified in the name, this method reads a line of text.
71
71
72
72
A line is considered to be terminated by any one of a line feed ('\n') or a carriage return ('\r').
@@ -82,12 +82,12 @@ import java.io.*;
82
82
83
83
/**
84
84
* A java program to read file line by line using the
85
-
* readLine() method of the BufferReader Class.
85
+
* readLine() method of the BufferedReader Class.
86
86
*
87
87
* @author Gaurav Kukade at coderolls.com
88
88
*
89
89
*/
90
-
publicclassBufferReaderReadLineMethodExample {
90
+
publicclassBufferedReaderReadLineMethodExample {
91
91
92
92
publicstaticvoidmain(String[] args) {
93
93
@@ -119,31 +119,33 @@ Welcome to coderolls.com!
119
119
120
120
Visit coderolls to read more coding tutorials!
121
121
```
122
-
See [this example on GitHub](https://github.com/coderolls/blogpost-coding-examples/blob/main/java-files-io/BufferReaderReadLineMethodExample.java).
122
+
See [this example on GitHub](https://github.com/coderolls/blogpost-coding-examples/blob/main/java-files-io/BufferedReaderReadLineMethodExample.java).
123
123
124
-
I have given below a combine example of the Java `BufferReader``read()` and `readLine()` method below
124
+
I have given below a combine example of the Java `BufferedReader``read()` and `readLine()` method below
0 commit comments