如何使用 FileWriter 在文件中追加文本

how do i append text inside a file using FileWriter

我一直在尝试向我的文件(内部存储)中添加文本 它被尝试使用 FileOutputStream 并且它很好但是在我改为使用 FileWriter 之后我开始出现只读文件系统错误

        EditText edd = findViewById(R.id.editTextData);
        Spinner spp = findViewById(R.id.spinnerCategory);

        String text1 = edd.getText().toString();
        String text2 = spp.getSelectedItem().toString();

        String filepath = text2 + ".txt";

        try {
            BufferedWriter bw = new BufferedWriter(new FileWriter(filepath, true));
            bw.write(text1);
            bw.newLine();
            bw.close();
            Toast.makeText(getBaseContext(), "Information Saved", Toast.LENGTH_SHORT).show();
        } catch (Exception e) {
            Toast.makeText(getBaseContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
        } //End try catch statement

    }```

It's supposed to say Information Saved but i keep getting read-only file system
    EditText edd = findViewById(R.id.editTextData);
    Spinner spp = findViewById(R.id.spinnerCategory);

    String text1 = edd.getText().toString();
    String text2 = spp.getSelectedItem().toString();

    String filename = text2 + ".dat";

    try {
        File fa = new File(getFilesDir(),filename); //getting the filename path
        FileWriter fw = new FileWriter(fa,true);
        fw.write(text1 + "\n");
        fw.close();
        Toast.makeText(getBaseContext(), "Information Saved", Toast.LENGTH_SHORT).show();
    } catch (Exception e)
    {
        Toast.makeText(getBaseContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
    } //End try catch statement