Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java System.getProperty(“line.separator”)不工作-Android Studio_Java_Android - Fatal编程技术网

Java System.getProperty(“line.separator”)不工作-Android Studio

Java System.getProperty(“line.separator”)不工作-Android Studio,java,android,Java,Android,目前,我有一个代码,检索网站纯文本并将其存储在文本文件中。我设法做到了这一点,但当我想在文本文件中输入一个新行时,它不起作用 我的成绩 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 co

目前,我有一个代码,检索网站纯文本并将其存储在文本文件中。我设法做到了这一点,但当我想在文本文件中输入一个新行时,它不起作用

我的成绩

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();
    }
}
publicsvoidstorehtml(上下文上下文、arrayliststorehtml、字符串地址){
试一试{
文件根=新文件(Environment.getExternalStorageDirectory().getAbsolutePath()+“/voicethenews”);
如果(!root.exists()){
root.mkdirs();
}
address=address.substring(address.lastIndexOf(“/”)+1);
文件gpxfile=新文件(根,地址+“.txt”);
FileWriter=新的FileWriter(gpxfile);
//FileOutputStream FileOutputStream=新的FileOutputStream(gpxfile);
//BufferedWriter BufferedWriter=new BufferedWriter(new OutputStreamWriter(fileOutputStream));
对于(int i=0;i

我尝试了多种代码和解决方案,但仍然不起作用。

如果您从HTML获得详细信息。因此,让我们使用

,而不是

这是将文本添加到文本视图
b

b.setText(Html.fromHtml("<b>" + st + "</b>" + "<br/>" + cursor.getString(1)));
b.setText(Html.fromHtml(“+st++”
“+cursor.getString(1));

参考资料:

此问题可能与您遇到的问题完全相同:


在1.7版之前的SDK中有一个bug,您必须直接调用环境变量。

我找到了它不能按预期显示的实际原因


它看起来不起作用的原因首先是因为我用默认的记事本打开了文本文件。当使用其他文本编辑器(如notepad++)打开时,文本文件中的输出按预期写入

如果要将HTML写入文件,则需要使用

而不是系统的行分隔符。我已按标题和段落提取纯文本,并将其存储在
ArrayList storeHTML
,“
是否仍然适用于此?您可能会被这个问题咬到:您可能会被这个问题咬到:您可能会被这个问题咬到: