简体   繁体   English

如何以精确的格式将 txt 文件从 url 解析为 textview?

[英]How to parse a txt file from a url in the exact format to a textview?

I am try to parse a txt file from a url to a textview in my application the text is being display but the text are not display in the right format as it is online like spaces, next line, paragraph etc.我试图在我的应用程序中将一个 txt 文件从 url 解析为 textview 文本正在显示,但文本没有以正确的格式显示,因为它像空格一样在线,下一行,段落 etZ4A8A08F0409D37B74B538539 simply put what i want is>简单地说我想要的是>

CHAPTER 1第1章

INTRODUCTION TO MOBILE移动简介

Majority of the population use mobile services.大多数人口使用移动服务。

Mobile is a term used via a mobile device such as a mobile phone.移动是通过移动设备(例如手机)使用的术语。

but I am getting但我得到

CHAPTER 1 INTRODUCTION TO MOBILE Majority of the population use mobile services.Mobile is a term used via a mobile device such as a mobile phone.<< no space, no paragraph, no next line, how can i parse it to display exactly the way it is online.Thanks第 1 章 MOBILE 简介 大多数人口使用移动服务。Mobile 是通过移动设备(例如手机)使用的术语。<< 没有空格,没有段落,没有下一行,我如何解析它以准确显示它在线。谢谢

public class GetNotePadFileFromServer extends AsyncTask<Void, Void, Void> {

    @Override
    protected Void doInBackground(Void... params) {

        try {
            url = new URL(TextFileURL);

            bufferReader = new BufferedReader(new InputStreamReader(url.openStream()));

            while ((TextHolder2 = bufferReader.readLine()) != null) {

                TextHolder += TextHolder2;
            }
            bufferReader.close();

        } catch (MalformedURLException malformedURLException) {
            malformedURLException.printStackTrace();
            TextHolder = malformedURLException.toString();

        } catch (IOException iOException) {
            iOException.printStackTrace();

            TextHolder = iOException.toString();
        }

        return null;

    }

    @Override
    protected void onPostExecute(Void finalTextHolder) {

        textView.setText(TextHolder);

        super.onPostExecute(finalTextHolder);
    }

}
        while ((TextHolder2 = bufferReader.readLine()) != null) {

            TextHolder += TextHolder2;

You read the text line by line.您逐行阅读文本。

Lines are separated by the newline character '\n'.行由换行符“\n”分隔。

So to restore the original text you should add them again.因此,要恢复原始文本,您应该再次添加它们。

            TextHolder += TextHolder2 + "\n";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM