【发布时间】:2016-08-29 05:59:15
【问题描述】:
目前我有一个代码,用于检索网站纯文本并将其存储在文本文件中。我设法做到了,但是当我想在文本文件中输入新行时,它不起作用。
我的结果
This is the article titleThis is the starting of the first paragraph
我想要什么
This is the article title
This the starting of the first paragraph
我的源代码
public void storeHTML(Context context, ArrayList<String> storeHTML, String address) {
try {
File root = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+ "/voicethenews");
if (!root.exists()) {
root.mkdirs();
}
address = address.substring(address.lastIndexOf("/") + 1);
File gpxfile = new File(root, address + ".txt");
FileWriter writer = new FileWriter(gpxfile);
//FileOutputStream fileOutputStream = new FileOutputStream(gpxfile);
//BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(fileOutputStream));
for(int i = 0; i < storeHTML.size(); i++) {
//bufferedWriter.write(storeHTML.get(i));
//bufferedWriter.newLine();
writer.append(storeHTML.get(i) + System.lineSeparator());
}
writer.flush();
writer.close();
Toast.makeText(context, "Saved", Toast.LENGTH_SHORT).show();
} catch (IOException e) {
e.printStackTrace();
}
}
我尝试了多种代码和解决方案,但仍然无法正常工作。
【问题讨论】:
-
如果是写HTML到文件,需要使用
<br />而不是系统的行分隔符 -
我已经按标题和段落提取了纯文本并存储在
ArrayList<String> storeHTML中,`
仍然适用吗? -
你可能被这个问题所困扰:System.lineSeparator() doesn't exist in android
-
你可能被这个问题所困扰:System.lineSeparator() doesn't exist in android
-
你可能被这个问题所困扰:System.lineSeparator doesn't exist in android