; electset.setIsReadDB(jo.getString("isReadDB")); return electset;}//设置属性,并保存public boolean setElect(String path,String sets){ try { writeFile(path,sets); return true; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); return false; }}//读文件,返回字符串public String ReadFile(String path){ File file = new File(path); BufferedReader reader = null; String laststr = ""; try { //System.out.println("以行为单位读取文件内容,一次读一整行:"); reader = new BufferedReader(new FileReader(file)); String tempString = null; int line = 1; //一次读入一行,直到读入null为文件结束 while ((tempString = reader.readLine()) != null) { //显示行号 System.out.println("line " line ": " tempString); laststr = laststr tempString; line ; } reader.close(); } catch (IOException e) { e.printStackTrace(); } finally { if (reader != null) { try { reader.close(); } catch (IOException e1) { } } } return laststr;} //把json格式的字符串写到文件public void writeFile(String filePath, String sets) throws IOException { FileWriter fw = new FileWriter(filePath); PrintWriter out = new PrintWriter(fw); out.write(sets); out.println(); fw.close(); out.close(); } 4.调用,使用(在网站的controller里调用的) //取出json对象public void GetElectSettings(HttpServletRequest request, HttpServletResponse response) throws Exception { ElectSet electset=new ElectSet(); String absPath = request.getRealPath(""); String filePath = absPath "publicsetselectSets.json"; electset=businessService.findElectSets(filePath);//这里是调用,大家自己改改,我调用的业务层 的。 JSONArray jsonItems = new JSONArray(); jsonItems.add(electset); JSONObject jo=new JSONObject(); jo.put("data", jsonItems); System.out.println(jo); request.setCharacterEncoding("utf-8"); response.setContentType("application/json;charset=utf-8"); PrintWriter out = response.getWriter(); out.print(jo);} //修改json文件public void ChangeElectSet(HttpServletRequest request, HttpServletResponse response) throws Exception {&nb