如何将 json 字符串附加到已经包含 json 字符串的文件(在 java 中)?我尝试使用 objectmapper 将文件读入内存,然后将其附加并放回文件中。
ObjectMapper mapper = new ObjectMapper();
HashMap<String, Object> jsonMap = mapper.readValue( new File(workflowSessionFilePath), new TypeReference<HashMap<String, Object>>() {});
jsonMap.put("key", "value");
mapper.defaultPrettyPrintingWriter().writeValue(new File(workflowSessionFilePath), jsonMap);
但是还有比这更好的方法吗?