-3
如何將json字符串附加到已包含json字符串的文件(在java中)? 我嘗試使用objectmapper將文件讀入內存,然後將其追加並放回到文件中。將json字符串附加到文件中
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);
但是有沒有比這更好的方法?
你如何解析和修改文件的內容?請提供代碼示例。 – 2013-07-06 01:24:40