自己写数据库,索引文件很大,加载会很慢,按理应该怎么处理?分文件?
如题:
请教一个事情,数据库的按照索引搜索数据很快,但是加载索引文件会很慢,应该怎么做避免这个问题呢?索引文件分小?
索引使用如下方式写文件,读文件了:
public static void writeObj2File(String fName, Object obj) {
try {
ObjectOutputStream oo = new ObjectOutputStream(new FileOutputStream(fName));
oo.writeObject(obj);
oo.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public static Object getObjFromFile(String fName) {
try {
ObjectInputStream oi = new ObjectInputStream(new FileInputStream(fName));
return oi.readObject();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return null;
}
百万的数据,60M的索引,加载出来后花了15秒左右。。。
希望大家能提供建议。谢谢大家了、