Modify a file using android studio

0

I need to modify the file that I show you below:

I have tried several ways but I always get an error. I leave the following code to know what I'm failing. Thank you very much.

try{
    FileOutputStream archivo= new FileOutputStream("assets/prueba.json",true);
    archivo.write("hola".getBytes());

    } catch (IOException e) {
            e.printStackTrace();
    }
    
asked by kosode 19.11.2018 в 15:02
source

1 answer

1

The Assets directory is read only, so you will not be able to write to it, but you can always use an internal file by doing something similar to:

String FILENAME = "prueba.json";
String string = "Esta es mi prueba";

FileOutputStream fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
fos.write(string.getBytes());
fos.close();

You can find more information on the subject in the Android developers guide: link

    
answered by 19.11.2018 / 15:51
source