-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpractice_src_zc_itevent_Demo07.java
More file actions
45 lines (33 loc) · 1.06 KB
/
Copy pathpractice_src_zc_itevent_Demo07.java
File metadata and controls
45 lines (33 loc) · 1.06 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
42
43
44
45
package zc.itevent;
import java.io.*;
import java.util.HashMap;
import java.util.Set;
/*
对D:\\out.txt中的文本进行排序
*/
public class Demo07 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new FileReader("d:\\out.txt"));
BufferedWriter bw = new BufferedWriter(new FileWriter("D:\\IdeaProjects\\secondary\\practice\\copy.txt"));
HashMap<String,String> map = new HashMap<>();
String s;
while ((s = br.readLine()) != null){
String[] split = s.split("\\.");
map.put(split[0],split[1]);
}
Set<String> keys = map.keySet();
for (String key : keys) {
String value = map.get(key);
bw.write(key+"."+value);
bw.newLine();
}
/* for (int i = 1; i <= map.size(); i++) {
String key = String.valueOf(i);
String value = map.get(key);
bw.write(key+"."+value);
bw.newLine();
}*/
bw.close();
br.close();
}
}