我尝试在我的应用程序中将 txt 文件从 url 解析为文本视图,文本正在显示,但文本没有以正确的格式显示,因为它是在线的,如空格、下一行、段落等,简单地说就是我想要的>第1章移动设备简介大多数人口使用移动服务。移动是通过移动设备(例如移动电话)使用的术语。但我越来越第一章移动简介 大多数人使用移动服务。移动是通过移动设备(例如手机)使用的术语。<< 没有空格,没有段落,没有下一行,我如何解析它以准确显示方式它在线。谢谢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); }}
1 回答

侃侃尔雅
TA贡献1801条经验 获得超16个赞
while ((TextHolder2 = bufferReader.readLine()) != null) { TextHolder += TextHolder2;
您逐行阅读文本。
行由换行符“\n”分隔。
因此,要恢复原始文本,您应该再次添加它们。
TextHolder += TextHolder2 + "\n";
添加回答
举报
0/150
提交
取消