首页 > 解决方案 > 为什么 BufferedReader 当它什么也没找到时给我异常

问题描述

我正在为 Android 平台编写一个应用程序。我的目的是;我从文本文件中搜索我在编辑文本上写的单词。做到这一点;我曾经使用 BufferedReader。(Txt 文件太大,以至于我用来编辑自定义属性)。当它在文本文件中找到我的话时,我的代码运行良好。但是当我搜索诸如“asdsad”之类的无意义的东西时。我的代码给了我例外。它是关于 BufferedReader 我该如何修复它?

自定义属性:

idea.max.intellisense.filesize=999999

我的代码:

String text = "";
        BufferedReader reader;

        try {
            InputStream is = getAssets().open("word_families_kopya.txt");
            reader = new BufferedReader(new InputStreamReader(is));
            String line = reader.readLine();

            String translating_string = editText_words.getText().toString();


while (!line.contains(translating_string) && line.toString() != null) {


    line = reader.readLine();

Log.i(TAG, "onClick:" + line); cevirilmis_textview.setText(line);

}


    } catch (IOException e) {
        e.printStackTrace();
    }finally {

    }



        } catch (IOException e) {
            e.printStackTrace();
        }finally {

        }

异常消息:

阅读:意外的EOF!

标签: androidstringbufferedreader

解决方案


推荐阅读