Write a string to a file

后端 未结 4 1899

I want to write something to a file. I found this code:

private void writeToFile(String data) {
    try {
        OutputStreamWriter outputStreamWriter = new Ou         


        
4条回答
  •  一生所求
    2021-01-31 18:42

    Write one text file simplified:

    private void writeToFile(String content) {
        try {
            File file = new File(Environment.getExternalStorageDirectory() + "/test.txt");
    
            if (!file.exists()) {
                file.createNewFile();
            }
            FileWriter writer = new FileWriter(file);
            writer.append(content);
            writer.flush();
            writer.close();
        } catch (IOException e) {
        }
    }
    

提交回复
热议问题