|
@@ -1,6 +1,10 @@
|
|
|
package com.zskk.service;
|
|
|
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileWriter;
|
|
|
import java.io.IOException;
|
|
|
+import java.nio.file.Files;
|
|
|
+import java.nio.file.Path;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
|
|
@@ -121,6 +125,10 @@ public class DataService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public static String fileToString(String path) throws IOException {
|
|
|
+ return Files.readString(Path.of(path));
|
|
|
+ }
|
|
|
+
|
|
|
public static void main(String[] args) {
|
|
|
Map <String,String> map = new HashMap<String,String>();
|
|
|
map.put("institution_id", "06300009");
|
|
@@ -130,7 +138,33 @@ public class DataService {
|
|
|
System.out.println(JSON.toJSONString(map));
|
|
|
// map.put("num", "10");
|
|
|
// postWithParameters(SAVE_REPORT_URL, map);
|
|
|
- postWithParameters(GET_KEY_URL, map);
|
|
|
- }
|
|
|
+ String content = postWithParameters(GET_KEY_URL, map);
|
|
|
+
|
|
|
+
|
|
|
+ File file = new File("./123-测试记录.txt");
|
|
|
+ try {
|
|
|
+ // 使用FileWriter不需要考虑原文件不存在的情况
|
|
|
+ // 当该文件不存在时,new FileWriter(file)会自动创建一个真实存在的空文件
|
|
|
+ FileWriter fileWriter = new FileWriter(file);
|
|
|
+ // 往文件重写内容
|
|
|
+ fileWriter.write(content);// 清空
|
|
|
+ fileWriter.flush();
|
|
|
+ fileWriter.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ String content2= fileToString("./123-测试记录.txt");
|
|
|
+
|
|
|
+ System.out.println("44"+content2);
|
|
|
+
|
|
|
+ } catch (IOException e) {
|
|
|
+ // TODO Auto-generated catch block
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
}
|