JsonGenerator appending json data to file without ovewriting
<p>I am reading bytes from a socket and then writing to a json file using jsonGenerator. Problem is JsonGenerator is overwriting the file everytime a stream is received from the socket. how do I make it append the subsequent streams instead of overwriting?</p>

<pre><code>JsonFactory factory = new JsonFactory();
        JsonGenerator generator = factory.createGenerator(
            new File("transactions.json"), JsonEncoding.UTF8);

            try {
        while ( (bytesRead = in.read(bytes)) != -1 ){ // -1 indicates EOF

            output= new String(bytes, "UTF-8");
            String length = output.substring(0, 4).trim();
            String mti = output.substring(4, 8).trim();
            String resp = "000";
            String newoutput = "";
            String bitmap = output.substring(8, 24);
            String stan = output.substring(24, 30);
            String date = output.substring(30, 44);
            String function_code = output.substring(44, 47);
            mti = "1814";


                // output to file

             generator.writeStartObject();
             generator.writeStringField("MTI", mti);
             generator.writeStringField("lenght", length);
             generator.writeStringField("stan", stan);
             generator.writeStringField("date", date);
             generator.writeStringField("Function Code", function_code);
                generator.writeEndObject();
           }
    } catch (Exception e) {
                System.out.println("Exceptions "+e);
            }finally{
                generator.close();

            }
</code></pre>

<p>Also when I declare generator outside the while loop  and close it outside the loop for some reason the data is not written to the file so I am assuming the generator kinda like buffers it and when you close it writes to the file. </p>