【问题标题】:Missing text file line breaks when opened in an Android app在 Android 应用中打开时缺少文本文件换行符
【发布时间】:2015-03-24 07:18:08
【问题描述】:

我有一个使用 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());

帮忙,有人吗?提前致谢!

【问题讨论】:

    标签: android eclipse stringbuffer datainputstream


    【解决方案1】:
    buffer.append(line).append(System.getProperty("line.separator"));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-22
      • 1970-01-01
      • 2015-12-01
      • 1970-01-01
      • 2019-06-23
      相关资源
      最近更新 更多