-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathFileHandler.java
34 lines (26 loc) · 985 Bytes
/
FileHandler.java
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
package BankManagementSystem;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
public class FileHandler {
// Specify the directory path where your data files are located
private static final String DATA_DIRECTORY = "data/";
public static List<String> readData(String fileName) throws IOException {
List<String> data = new ArrayList<>();
try (BufferedReader reader = new BufferedReader(new FileReader(DATA_DIRECTORY + fileName))) {
String line;
while ((line = reader.readLine()) != null) {
data.add(line);
}
}
return data;
}
public static void writeData(String fileName, List<String> data) throws IOException {
try (BufferedWriter writer = new BufferedWriter(new FileWriter(DATA_DIRECTORY + fileName))) {
for (String line : data) {
writer.write(line);
writer.newLine();
}
}
}
}