|
@@ -1,14 +1,14 @@
|
|
|
package cn.cslg.pas.service.query;
|
|
|
|
|
|
import cn.cslg.pas.common.utils.parseQueryToTree.*;
|
|
|
+import com.google.gson.Gson;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.context.annotation.Lazy;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.LinkedList;
|
|
|
-import java.util.List;
|
|
|
+import java.io.*;
|
|
|
+import java.util.*;
|
|
|
|
|
|
@Service
|
|
|
@Slf4j
|
|
@@ -85,4 +85,45 @@ public class QueryService {
|
|
|
return strCode;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ public void write() {
|
|
|
+ // 创建一个Map对象并添加一些数据
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
+ map.put("key1", "value1");
|
|
|
+ map.put("key2", "value2");
|
|
|
+ map.put("key3", "value3");
|
|
|
+
|
|
|
+ // 将Map存储到文件中
|
|
|
+ try {
|
|
|
+ FileOutputStream fileOut = new FileOutputStream("map.ser");
|
|
|
+ ObjectOutputStream out = new ObjectOutputStream(fileOut);
|
|
|
+ out.writeObject(map);
|
|
|
+ out.close();
|
|
|
+ fileOut.close();
|
|
|
+ System.out.println("Map已经成功存储到文件中");
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Map<String, Object> readJsonFile(String fileName) {
|
|
|
+ Gson gson = new Gson();
|
|
|
+ String json = "";
|
|
|
+ try {
|
|
|
+ File file = new File("target/file/test.json");
|
|
|
+ Reader reader = new InputStreamReader(new FileInputStream(file), "utf-8");
|
|
|
+ int ch = 0;
|
|
|
+ StringBuffer buffer = new StringBuffer();
|
|
|
+ while ((ch = reader.read()) != -1) {
|
|
|
+ buffer.append((char) ch);
|
|
|
+ }
|
|
|
+ reader.close();
|
|
|
+ json = buffer.toString();
|
|
|
+ return gson.fromJson(json, Map.class);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|