-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIndexSplit.java
executable file
·52 lines (47 loc) · 1.41 KB
/
IndexSplit.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
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.*;
import java.util.*;
import java.lang.*;
public class IndexSplit {
public static void main(final String[] argv) throws Exception {
String index = "temp/block.txt";
String chf = "$";
boolean str = false;
File statText = new File("index/"+"$.txt");
statText.getParentFile().mkdirs();
statText.createNewFile();
FileOutputStream is = new FileOutputStream(statText);
OutputStreamWriter osw = new OutputStreamWriter(is);
Writer w = new BufferedWriter(osw);
try(BufferedReader br = new BufferedReader(new FileReader(index))) {
for(String line; (line = br.readLine()) != null; ) {
String line_head = line.substring(0,line.indexOf(':'));
String bla = "$";
if(line_head.length()==1)
bla = ""+line_head.charAt(0);
else
bla = line.substring(0,2);
if(line_head != null && !bla.equals(chf))
{
chf = bla;
w.close();
statText = new File("index/"+chf+".txt");
statText.createNewFile();
is = new FileOutputStream(statText);
osw = new OutputStreamWriter(is);
w = new BufferedWriter(osw);
str = false;
}
if(str)
w.write('\n');
str=true;
w.write(line);
// process the line.
}
// line is not visible here.
}
}
}