-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathreadwrite.java
More file actions
45 lines (32 loc) · 1.11 KB
/
readwrite.java
File metadata and controls
45 lines (32 loc) · 1.11 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
41
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
// Reads a file
public class readWrite {
public readWrite(String inputFile) throws IOException {
File file = new File(inputFile);
BufferedReader reader = new BufferedReader(new FileReader(file));
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
reader.close();
}
// Asks for a file and a text string, writes the string into the file
public void writeCode(String codeFile, String text) throws IOException {
try (PrintWriter writer = new PrintWriter(codeFile)) {
writer.println(text);
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
try {
readWrite rw = new readWrite("input.txt");
rw.writeCode("output.txt", "aidan rahill is my baby boy i love him");
} catch (IOException e) {
e.printStackTrace();
}
}}