-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBRE.java
More file actions
40 lines (31 loc) · 1.03 KB
/
BRE.java
File metadata and controls
40 lines (31 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import java.io.*;
public class BRE {
public static void main(String[] args) {
String fileName = "test.txt";
// 🔹 Using FileReader (character by character)
try {
FileReader fr = new FileReader(fileName);
int ch;
System.out.println("Reading using FileReader:");
while ((ch = fr.read()) != -1) {
System.out.print((char) ch);
}
fr.close();
} catch (Exception e) {
System.out.println(e);
}
System.out.println("\n------------------------\n");
// 🔹 Using BufferedReader (line by line)
try {
BufferedReader br = new BufferedReader(new FileReader(fileName));
String line;
System.out.println("Reading using BufferedReader:");
while ((line = br.readLine()) != null) {
System.out.println(line);
}
br.close();
} catch (Exception e) {
System.out.println(e);
}
}
}