日期:2014-05-20 浏览次数:20726 次
public void saveAsDay(){ SimpleDateFormat dataFormat=new SimpleDateFormat("yyyy-MM-dd'.txt'"); String sToday=dataFormat.format(new Date()).toString(); boolean hasToday=false; try{ File dir=new File("./"); String filename[]=dir.list(); for(int i=1;i<filename.length;i++){ if(filename[i].equals(sToday)) hasToday=true; } File acc=new File("./","account.txt"); acc.createNewFile(); if(hasToday){ String s,tmp=""; { FileReader dataReader=new FileReader(acc); BufferedReader readData=new BufferedReader(dataReader); while((s=readData.readLine())!=null) tmp+=(s+"\n"); readData.close(); dataReader.close(); acc.delete(); } { File today=new File("./",sToday); FileWriter dataWriter=new FileWriter(today,true); BufferedWriter writeData=new BufferedWriter(dataWriter); writeData.write(tmp); writeData.close(); dataWriter.close(); } } else{ acc.renameTo(new File("./",sToday)); } }