android - How to append items to JSON file without parsing and rewriting -


i generating observation objects , want add them json file. way i'm doing now, i'm parsing existing file , converting json object, adding new observation instance retrieved collection, parsing json , re-writing file.

here's code:

final file file = getfile(); final observationset observationset = retrievepreviousobservations(file);  observationset.getobservations().add(observation[0]);  final outputstream os = new fileoutputstream(file); os.write(gsonhelper.tojson(observationset).getbytes()); os.close(); 

...

private observationset retrievepreviousobservations(final file file) {     observationset observationset = new observationset();     try {         final bufferedreader br = new bufferedreader(new filereader(file));         observationset = gsonhelper.getgson().fromjson(br, observationset.class);     } catch (filenotfoundexception e) {         log.w(tag, "no previous file found, first entry", e);     }     return observationset; } 

the problem is, observation objects quite big , after several tens of entries, appending process takes long time (generally more 10 seconds 20+ items in collection).

is there way append existing json file without having parse existing one, adding object, parsing , rewriting file?


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -