使用文本做缓冲

来源:互联网 发布:美发上门服务app软件 编辑:程序博客网 时间:2024/06/15 15:45

写入文本:

    //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()方法;




原创粉丝点击