62,614
社区成员
发帖
与我相关
我的任务
分享
public class Location {
private String[] s;
private int num_line = 0;
private int real_start = 0; //前面声明的行数
//(最终real_start对应的值即为第一行有用数据在s数组中的下标)
//初始化File中的每一行字符串,并存入s数组中
public Location(File f) throws IOException {
//统计行数
BufferedReader br = new BufferedReader(new FileReader(f));
while(br.readLine() != null) {
++num_line;
}
br.close();
//存入到s数组中
br = new BufferedReader(new FileReader(f));
s = new String[num_line+1];
int cnt = 0; // 当前处理的行
while((s[cnt] = br.readLine()) != null) {
if(s[cnt].startsWith(" ")) {
++real_start;
}
++cnt;
}
br.close();
}
public void init() throws IOException{
index_noun = new Location(new File("./dict/index.noun"));
index_verb = new Location(new File("./dict/index.verb"));
index_adj = new Location(new File("./dict/index.adj"));
index_adv = new Location(new File("./dict/index.adv"));
data_noun = new Location(new File("./dict/data.noun"));
data_verb = new Location(new File("./dict/data.verb"));
data_adj = new Location(new File("./dict/data.adj"));
data_adv = new Location(new File("./dict/data.adv"));
lex_file = new Location(new File("./dict/lex_file.txt"));
}
StringBuffer strB = new StringBuffer();
strB.append("");
String s = "";
while((s = br.readLine()) != null) {
if(s.startsWith(" ")) {
++real_start;
}
++cnt;
}