/** * @param userInfoMap 注册用户的相关信息 * @throws IOException FileNotFoundException * @return 将用户信息写入csv文件中 */ public static void WriteCSV(Map<String,String> userInfoMap){ try { // 存储经销商ID和经销商微信信息的文件路径 String csvPath = FileUtil.getWorkingPath() .resolve(ConfigUtil.getConfig().get("idmappings")).toString(); //在原来内容上追加,如果true改为false或者默认没有的话会把原来的内容删掉,再添加 FileOutputStream fileOutputStream = new FileOutputStream(csvPath,true); //UTF-8写入,防止乱码 OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fileOutputStream, "UTF-8"); // 追记模式 BufferedWriter bw = new BufferedWriter(outputStreamWriter); // 新增一行数据 bw.newLine(); bw.write(userInfoMap.get("openId") + "," +userInfoMap.get("deptId")+ "," + userInfoMap.get("deptName")+ "," + userInfoMap.get("roleName")); bw.close(); } catch (FileNotFoundException e) { // 捕获File对象生成时的异常 e.printStackTrace(); } catch (IOException e) { // 捕获BufferedWriter对象关闭时的异常 e.printStackTrace(); } }
本文出自 “羽鸿出品” 博客,请务必保留此出处http://5fresh.blog.51cto.com/5472694/1433839
原文地址:http://5fresh.blog.51cto.com/5472694/1433839