我一直试图打开这个 .json 文件一段时间,它给了我一个空指针异常。如果我做错了什么,请告诉我。
/**
* Handles requests for the application UI.
*/
@Controller
@RequestMapping("/UIController")
public class UIController {
private static final Logger logger = LoggerFactory.getLogger(UIController.class);
private @Autowired ServletContext servletContext;
@RequestMapping(value = "/ClientTree", method = RequestMethod.GET)
public @ResponseBody String clientTree() throws IOException {
InputStream inputStream = null;
try {
inputStream = servletContext.getResourceAsStream("C:\\ClientJson.json");
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
return bufferedReader.readLine();
} finally {
if (inputStream != null) {
inputStream.close();
}
}
}
}
我正在尝试打开并读取文件内容,将这些内容发送到 UI 以填充树 jQuery 小部件。