我想直接搜索文本文件而不将其存储到arraylist或任何数组中,文本文件将包含大约100,000个单词。我想使用二进制搜索执行搜索以查找特定单词并显示其含义。有可能这样做吗?有没有我可以参考的样品,这样做?文本文件将充当数据库。
谢谢。
答案 0 :(得分:0)
在这里,希望这有助于......:
File file = new File(your file);
try {
FileInputStream in = new FileInputStream(file);
int len = 0;
byte[] data1 = new byte[1024];
while ( -1 != (len = in.read(data1)) ){
if(new String(data1, 0, len).contains(Your String))
//Jim, we got him...
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}