標籤:rac ext phone return ogg tac list close isis
Java實現文本建立並追加內容
1,建立文本代碼:
//建立檔案並追加內容public static void writeContentToTxt(StringBuffer Content,File f){ FileWriter fw = null; try { //如果檔案存在,則追加內容;如果檔案不存在,則建立檔案 //File f=new File("D:\\hei.txt"); fw = new FileWriter(f, true); } catch (IOException e) { e.printStackTrace(); } PrintWriter pw = new PrintWriter(fw); pw.println(Content); pw.flush(); try { fw.flush(); pw.close(); fw.close(); } catch (IOException e) { e.printStackTrace(); }}
2,追加內容到文本:
public boolean saveText(List<BaseInfo> list ){ Date dt=new Date(); SimpleDateFormat matter1=new SimpleDateFormat("yyyyMMdd"); String date = matter1.format(dt); boolean flag = true; String filefullpath = Pub.getPropertiesValue("analysis", "dataPathDir")+"_.txt"; File anaylisisFile = new File (filefullpath); for(BaseInfo baseInfo : list ){ StringBuffer suf = new StringBuffer(); suf.append(date); suf.append("|&@"); suf.append(baseInfo.getOp_station()); suf.append("|&@"); suf.append(baseInfo.getIp()); suf.append("|&@"); suf.append(baseInfo.getMac()); suf.append("|&@"); suf.append(baseInfo.getPhone()); suf.append("|&@|"); logger.info("saveTxt suf:"+suf); writeContentToTxt(suf,anaylisisFile); } return flag;}
Java實現文本建立並追加內容