记得上下班打卡 | git大法好,push需谨慎

Commit ac3a3aba authored by GaoHu's avatar GaoHu

读取省市区json文件

parent a3955b51
...@@ -16,10 +16,7 @@ import org.springframework.stereotype.Controller; ...@@ -16,10 +16,7 @@ import org.springframework.stereotype.Controller;
import org.springframework.util.ResourceUtils; import org.springframework.util.ResourceUtils;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.io.File; import java.io.*;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.List; import java.util.List;
/** /**
...@@ -110,8 +107,10 @@ public class SmileUserController extends BaseController { ...@@ -110,8 +107,10 @@ public class SmileUserController extends BaseController {
try { try {
String path = JSONUtils.class.getClassLoader().getResource("static/area.json").getPath(); String path = JSONUtils.class.getClassLoader().getResource("static/area.json").getPath();
File jsonFile = ResourceUtils.getFile(path); File jsonFile = ResourceUtils.getFile(path);
logger.info("path:{}",path);
// File jsonFile = ResourceUtils.getFile("classpath:static/area.json"); // File jsonFile = ResourceUtils.getFile("classpath:static/area.json");
Reader reader = new InputStreamReader(new FileInputStream(jsonFile), "utf-8"); InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("static/area.json");
Reader reader = new InputStreamReader(inputStream, "utf-8");
int ch = 0; int ch = 0;
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
while ((ch = reader.read()) != -1) { while ((ch = reader.read()) != -1) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment