-
Notifications
You must be signed in to change notification settings - Fork 0
/
qb307.java
54 lines (41 loc) · 1.23 KB
/
qb307.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import java.io.*;
import java.util.*;
import java.util.Collections;
class QB307 {
public static void main(String[] args) throws IOException {
File f = new File("qb.txt");
FileWriter fw = new FileWriter(f);
BufferedWriter bw = new BufferedWriter(fw);
ArrayList<Integer> al = new ArrayList<>();
bw.write("1");
bw.newLine();
bw.write("55");
bw.newLine();
bw.write("12");
bw.newLine();
bw.write("33");
bw.newLine();
bw.write("80");
bw.close();
FileReader fr = new FileReader("qb.txt");
BufferedReader br = new BufferedReader(fr);
String read = br.readLine();
while (read != null) {
int number = Integer.parseInt(read);
al.add(number);
read = br.readLine();
}
br.close();
// Sorting
Collections.sort(al);
File f2 = new File("newQb.txt");
FileWriter fr2 = new FileWriter(f2);
BufferedWriter bww = new BufferedWriter(fr2);
for (Integer i : al) {
bww.write(Integer.toString(i));
bww.newLine();
}
bww.close();
System.out.println("File Sorted..");
}
}