| | |
| | | package com.stylefeng.guns.modular.system.service.impl; |
| | | |
| | | import cn.hutool.core.io.FileUtil; |
| | | import cn.hutool.core.util.CharsetUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.baomidou.mybatisplus.service.impl.ServiceImpl; |
| | |
| | | file.createNewFile(); |
| | | } |
| | | //写入相应的文件 |
| | | PrintWriter out = new PrintWriter(new FileWriter(file)); |
| | | orderPositions.add(orderPosition); |
| | | System.err.println("存储新数据:" + JSON.toJSONString(orderPositions)); |
| | | out.write(JSON.toJSONString(orderPositions)); |
| | | out.flush(); |
| | | out.close(); |
| | | FileUtil.writeUtf8String(JSON.toJSONString(orderPositions), file); |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | |
| | | return new ArrayList<>(); |
| | | } |
| | | //读取文件(字符流) |
| | | BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file),"UTF-8")); |
| | | //循环取出数据 |
| | | String str = null; |
| | | StringBuffer sb = new StringBuffer(); |
| | | while ((str = in.readLine()) != null) { |
| | | sb.append(str); |
| | | } |
| | | String s = FileUtil.readString(file, CharsetUtil.CHARSET_UTF_8); |
| | | List<OrderPosition> list = new ArrayList<>(); |
| | | if(ToolUtil.isNotEmpty(sb.toString())){ |
| | | list = JSONArray.parseArray(sb.toString(), OrderPosition.class); |
| | | if(ToolUtil.isNotEmpty(s)){ |
| | | list = JSONArray.parseArray(s, OrderPosition.class); |
| | | } |
| | | System.err.println("坐标:" + sb); |
| | | return list; |
| | | } |
| | | } |