-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileOperations.java
More file actions
30 lines (28 loc) · 949 Bytes
/
FileOperations.java
File metadata and controls
30 lines (28 loc) · 949 Bytes
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
// FileOperations.java
import java.io.*;
public class FileOperations {
public static void writeFile(String filename, String data) {
try {
FileWriter writer = new FileWriter(filename, true);
writer.write(data + "\n");
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public static String readFile(String filename) {
StringBuilder content = new StringBuilder();
try {
FileReader reader = new FileReader(filename);
BufferedReader bufferedReader = new BufferedReader(reader);
String line;
while ((line = bufferedReader.readLine()) != null) {
content.append(line).append("\n");
}
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
return content.toString();
}
}