I’m trying to append a new line to .txt file using Scoped Storage, I’ve already can create it and add text, but I haven’t be able to add/append a new line with text, I’m trying to use the FileOutputStream in MODE_APPEND but is giving me the red underline error, the Show Context Actions don’t help me either. Is like the MODE_APPEND doesn’t work with the ParcelFileDescriptor. Any suggestion would be appreciated. this is the onClick function:
add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
try {
String txt01=texto.getText().toString();
String txt02="TEXTVARMANUAL";
DocumentFile directory=DocumentFile.fromTreeUri(context,baseDocTreeUri);
DocumentFile file=directory.findFile(name.getText().toString());
ParcelFileDescriptor pfd= context.getContentResolver().openFileDescriptor(file.getUri(),"rw");
FileOutputStream fos=new FileOutputStream(pfd.getFileDescriptor(),MODE_APPEND); //<----ERROR!!
String alltxt =txt02+";"+txt01+",final.";
BufferedWriter writer=new BufferedWriter(new OutputStreamWriter(fos,"UTF-8"));
writer.write(alltxt);
writer.newLine();
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
});
1