-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathAns 2
More file actions
37 lines (32 loc) · 1.04 KB
/
Ans 2
File metadata and controls
37 lines (32 loc) · 1.04 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
import java.io.*;
public class ReadFile {
public static void main(String[] args) throws Exception {
FileWriterCustom fwc = new FileWriterCustom();
fwc.fileWriter();
fwc.reverseIntCustom();
}
}
class FileWriterCustom {
void fileWriter() throws Exception {
int i;
PrintWriter out = new PrintWriter(new FileWriter("one.txt"));
// loop to write 1 to thousand to a file
for (i = 100; i < 150; i++) {
out.println(i);
out.flush();
}
}
void reverseIntCustom() throws IOException {
BufferedReader reader = new BufferedReader(new FileReader("one.txt"));
PrintWriter out1 = new PrintWriter(new FileWriter("two.txt"));
String line = reader.readLine();
out1.println("Printing Reverse ");
while (line != null) {
String reversed = new StringBuilder(line).reverse().toString();
out1.println(reversed);
out1.flush();
line = reader.readLine();
}
reader.close();
}
}