写入文本:
//resData可以为Map类型或者是JSONObject类型,给resData一个标识,读取的时候方便判断
File cacheFile=new File(new File(PathKit.getRootClassPath()).getParentFile().getParentFile().getAbsolutePath()+"/cache/bigSegCommon.json");
FileUtil.writeUtf8String(resData.toString(), cacheFile);
读取文本:
File cacheFile=new File(new File(PathKit.getRootClassPath()).getParentFile().getParentFile().getAbsolutePath()+"/cache/bigSegCommon.json");
if(!FileUtil.exist(cacheFile)){
FileUtil.touch(cacheFile);
FileUtil.writeUtf8String("{}", cacheFile);
}
String cacheData = FileUtil.readUtf8String(cacheFile);
JSONObject cacheJson = JSONObject.fromObject(cacheData);
if(cacheJson.get("date") != null&&cacheJson.get("date").toString().equals(nowData)){
return cacheJson;
}
注意:写入的时候可以先转化为jsonObject再调用toString()方法;