package log;
import java.io.File; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Calendar;
public class LogTool {
/** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { String c_fileName= "d://mylog.log"; LogTool tool = new LogTool(); File file = new File(c_fileName); if(!file.exists()){ file.createNewFile(); } if(file.length() > 10){ tool.changeFile(file); }
} public void changeFile(File file){ if(file.exists()){ Calendar cal = Calendar.getInstance(); SimpleDateFormat formate = new SimpleDateFormat("yyyy-mm-dd_hh-mm-ss"); String time = formate.format(cal.getTime()); String newFileName = "d://" + time + ".log"; System.out.println(newFileName); File newfile = new File(newFileName); boolean flag = file.renameTo(newfile); if(flag == false){ } file = newfile; System.out.println(flag); } }
}