Create enter (new line) automaticly text file in a

2019-09-05 04:40发布

I made a create file app in android, I want to write a string variable to file.txt, and it should automatically insert an enter (navigate to new line)

I used:

public void cekFile() {
    File root = Environment.getExternalStorageDirectory();
    try {
        BufferedWriter fw = new BufferedWriter(new FileWriter(new File(
                "/data/log/log.txt"), true));
        if (root.canWrite()) {
            fw.write("Monitoring Panggilan" + "\n");
            fw.close();
        }
    } catch (IOException e) {
        Log.e("One", "Could not write file " + e.getMessage());
    }
}

It's not navigating to new line.

1条回答
等我变得足够好
2楼-- · 2019-09-05 05:03

Use the fw.newLine() method before or after the fw.write() method.

查看更多
登录 后发表回答