下面的方式是根据每张数据表生成一个json文件,list表示每张表数据,同时,在导入json数据文件的时候,改造下也可以用下面的方法,实际就是遍历所有的key和value
private String fileCreate(List<Map<String,Object>> list,String filepath) throws ParseException {
String flag=""; DESCipherImpl pbe = new DESCipherImpl(); StringBuffer sb = new StringBuffer(); FileWriter fw=null; BufferedWriter writer =null; try { File filename = new File(filepath); if(!filename.exists()){ filename.createNewFile(); } if(null!=list&&list.size()>0){ fw = new FileWriter(filepath); writer = new BufferedWriter(fw); for(int k =0;k<list.size();k++){ Map<String,Object> map =(Map)list.get(k); Iterator it=map.keySet().iterator(); JSONObject json = new JSONObject(); while(it.hasNext()) { String key =Convert.trimNull(it.next()); String value=Convert.trimNull(map.get(key)); } json.put(key, value); } sb.append(json.toString()).append("\r\n"); } //writer.write(sb.toString()); writer.write(pbe.encryptStr(sb.toString())); writer.flush(); return flag; }else{ flag=""; } } catch (IOException e) { flag="出现问题......"; return flag; }finally{ if(writer!=null){ try { writer.close(); } catch (IOException e) { e.printStackTrace(); } } if(fw!=null){ try { fw.close(); } catch (IOException e) { e.printStackTrace(); } } } return flag; }