将文件中的作为对象读取出来
File ff = new File("src\\test\\resources\\misc\\data.txt");
ObjectMapper mapper = new ObjectMapper();
//将json文件读取出来,变为一个对象,为了和新的回测数据进行对比
String str = null;//可以直接读文件 文件中为json数据
try {
str = FileUtils.readFileToString(ff);
Object o= mapper.readValue(str, Object.class);
System.out.println(o);
} catch (IOException e) {
e.printStackTrace();
}
将对象已json的格式写入文件中
Object o= getObject();
ObjectMapper mapper = new ObjectMapper();
//将对象存入json文件中
try {
mapper.writeValue(new File("src\\test\\resources\\misc\\SBTOldData.txt"),o);
} catch (IOException e) {
System.out.println(e);
e.printStackTrace();
}
}