Repository navigation
Expand file tree
/
Copy pathTotalCount.java
More file actions
60 lines (50 loc) · 1.66 KB
/
Copy pathTotalCount.java
File metadata and controls
60 lines (50 loc) · 1.66 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package file;
import minheap.HeapSort;
import minheap.MapHeapSort;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* Created by zhengyong on 17/4/18.
*/
public class TotalCount {
private static final int maxCount = 100;
private static final String filePath = "/Users/zhengyong/url.txt";
private static List<Map<String, Integer>> urlMap = new ArrayList<>(maxCount);
public static void main(String[] args) throws Exception {
FileReader fr = new FileReader(filePath);
BufferedReader buf = new BufferedReader(fr);
String line;
while ((line = buf.readLine()) != null) {
int mod = Math.abs(line.hashCode()) % 100;
System.out.println(mod);
writeFile(line, mod);
}
buf.close();
}
public static boolean writeFile(String content, int index) {
String filename = "/Users/zhengyong/url/" + index + "_url.txt";
try {
File f = new File(filename);
if (!f.exists()) {
f.createNewFile();
}
OutputStreamWriter write = new OutputStreamWriter(new FileOutputStream(f,true));
BufferedWriter writer = new BufferedWriter(write);
writer.write(content);
writer.flush();
write.close();
writer.close();
return true;
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
}