如何将 url 中的 txt 文件以精确格式解析为文本视图?
How to parse a txt file from a url in the exact format to a textview?
我正在尝试将 txt 文件从 url 解析为我的应用程序中的文本视图,正在显示文本,但文本未以正确的格式显示,因为它像空格一样在线,下一行, 第 e.t.c 段。简单地说我想要的是>
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.
但我得到了
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);
}
}
while ((TextHolder2 = bufferReader.readLine()) != null) {
TextHolder += TextHolder2;
您逐行阅读文本。
行由换行符'\n'分隔。
所以要恢复原文你应该重新添加它们。
TextHolder += TextHolder2 + "\n";
我正在尝试将 txt 文件从 url 解析为我的应用程序中的文本视图,正在显示文本,但文本未以正确的格式显示,因为它像空格一样在线,下一行, 第 e.t.c 段。简单地说我想要的是>
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.
但我得到了
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);
}
}
while ((TextHolder2 = bufferReader.readLine()) != null) {
TextHolder += TextHolder2;
您逐行阅读文本。
行由换行符'\n'分隔。
所以要恢复原文你应该重新添加它们。
TextHolder += TextHolder2 + "\n";