我的文本文件存储在assets文件夹中,我的要求是在文本视图中逐点显示内容。如果文本文件中没有空格存储在assets文件夹中,我可以访问内容。如果我放置空间在文本文件中然后我无法获取空格后的内容。如何实现这意味着逐点显示内容。 例如我的文本文件如下
A)Americab)Africac)印度
我希望输出为
a)美国
b)非洲
c)印度Here is my code to access the text file from assest folder which I am getting.
InputStream in = this.getAssets().open("detailtext.txt");
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
line = reader.readLine();
答案 0 :(得分:7)
由于你需要读取多行,你需要循环,直到你达到EOF。尝试这样的事情: -
StringBuffer sb = new StringBuffer(0);
InputStream in = this.getAssets().open("detailtext.txt");
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
String line = null;
while((line = reader.readLine()) != null){
sb.append(line);
sb.append("\n");
}
String wholeText = sb.toString();
答案 1 :(得分:1)
你只读一行,你需要使用while循环并继续读取每一行直到文件结尾
InputStream in = this.getAssets().open("detailtext.txt");
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
while((line = reader.readLine()) != null){
// do whatever with line
}