Please fix this JAVA code so that it will not overwrite the contents of the file every time I click on a row  @Override public void valueChanged(ListSelectionEvent event) { File file = new File("sample json file"); int row = table.getSelectedRow(); JSONObject obj = (JSONObject) jsonArray.get(row); ObjectMapper mapper = new ObjectMapper(); mapper.enable(SerializationFeature.INDENT_OUTPUT); try { JsonGenerator g = mapper.getFactory().createGenerator(new FileOutputStream(file)); mapper.writeValue(g, obj); g.close(); } catch (IOException e) { throw new RuntimeException(e); } } });

CMPTR
3rd Edition
ISBN:9781337681872
Author:PINARD
Publisher:PINARD
Chapter22: Integrating Word, Excel, Access, And Powerpoint
Section: Chapter Questions
Problem 4QY
icon
Related questions
Question

Please fix this JAVA code so that it will not overwrite the contents of the file every time I click on a row 

@Override
public void valueChanged(ListSelectionEvent event) {
File file = new File("sample json file");
int row = table.getSelectedRow();
JSONObject obj = (JSONObject) jsonArray.get(row);
ObjectMapper mapper = new ObjectMapper();
mapper.enable(SerializationFeature.INDENT_OUTPUT);

try {
JsonGenerator g = mapper.getFactory().createGenerator(new FileOutputStream(file));
mapper.writeValue(g, obj);
g.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
});

Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
File Input and Output Operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
CMPTR
CMPTR
Computer Science
ISBN:
9781337681872
Author:
PINARD
Publisher:
Cengage