0

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 e.t.c. simply put what i want is>

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.

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

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);
    }

}
4

1 回答 1

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

            TextHolder += TextHolder2;

您逐行阅读文本。

行由换行符“\n”分隔。

因此,要恢复原始文本,您应该再次添加它们。

            TextHolder += TextHolder2 + "\n";
于 2019-09-29T09:31:06.240 回答