gpt4 book ai didi

java - Android/Java文本文件读取问题

转载 作者:行者123 更新时间:2023-12-01 05:39:26 25 4
gpt4 key购买 nike

我目前正在尝试使用我这样标注的输入流从(res/raw)读取文件:

InputStream mStream = this.getResources().openRawResource(R.raw.my_text_file_utf_8);

然后我将其放入此方法中以返回值:

public List<String> getWords(InputStream aFile) {

List<String> contents = new ArrayList<String>();
try {
BufferedReader input = new BufferedReader(new InputStreamReader(aFile));
try {
String line = new String();//not declared within while loop
while ((line = input.readLine()) != null ){
contents.add(line);
}
}
finally {
input.close();
}
}
catch (IOException ex){
ex.printStackTrace();
}

return contents;

}

我的问题:它会按应有的方式读取所有值,但是假设文件的长度是104行,那么它实际上会返回类似的值> 总共 134 行 行,其余 30 行全部为空

已检查:已使用 UTF-8 格式,并仔细检查文档本身没有空行...

我认为 while 循环的编写方式无法将 line=null 值记录到内容列表中?我在这里遗漏了什么吗?

感谢您提供任何建设性信息!我很确定我在这里忽略了一些简单的事实......

最佳答案

为什么不为您的信息创建 HTML,然后解析它。

关于java - Android/Java文本文件读取问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7520331/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com