我有一个简单的程序,使用ScrollView和TextView显示一个长文本文件,但它似乎删除了它中的换行符。例如,如果文本文件实际上有
Bunnies are mean.
But it's okay.
Because they're fluffy.
显示为
Bunnies are mean. But it's okay. Because they're fluffy.
这就是我的代码:
txt = (TextView)findViewById(R.id.txt);
stream = getResources().openRawResource(R.drawable.textBunny);
DataInputStream d = new DataInputStream(stream);
String line=null;
StringBuffer buffer=new StringBuffer();
try {
while((line=d.readLine())!=null){
buffer.append(line);
}
} catch (IOException e) {
e.printStackTrace();
}
txt.setText(buffer.toString());
帮助,有人吗?提前谢谢!
答案 0 :(得分:1)
buffer.append(line).append(System.getProperty("line.separator"));