【问题标题】:how to perform search on a txt file directly?如何直接对txt文件进行搜索?
【发布时间】:2013-11-16 06:28:54
【问题描述】:

我想直接对文本文件执行搜索,而不将其存储到数组列表或任何数组中,并且该文本文件将包含大约 100,000 个单词。我想使用二进制搜索来执行搜索以查找特定单词并显示其含义。有可能这样做吗?有没有我可以参考的样本来做到这一点?文本文件将充当数据库。

谢谢。

【问题讨论】:

  • 为什么不直接使用数据库?会更快更方便。
  • 很遗憾地说我的任务不允许我将其存储到数据库中,但我将不得不使用 txt 文件。

标签: android algorithm search text


【解决方案1】:

给你,希望对你有帮助……:

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();
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-13
    • 2012-04-18
    • 2014-01-06
    • 1970-01-01
    相关资源
    最近更新 更多