import java.io.FileOutputStream;
import java.io.*;
import java.io.OutputStreamWriter;
import java.text.SimpleDateFormat;
import java.util.Calendar;
public class test {
static int sum = 0;
public static String getTodayDate(String flag){
String todayDate = "";
Calendar calendar = Calendar.getInstance();
SimpleDateFormat dateFormat = null;
if( "1".equals(flag) ){
dateFormat = new SimpleDateFormat("yyyyMMdd");
}else if("2".equals(flag)){
dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
}
todayDate = dateFormat.format(calendar.getTime());
return todayDate;
}
public static void main(String args[])throws IOException{
String log_content = "test" ;
String file_header = "D:/";
String file_tail = ".log";
String file_name = getTodayDate("1");
String file_path = file_header + file_name + file_tail ;
FileOutputStream fos = null;
OutputStreamWriter osw = null;
try{
fos = new FileOutputStream( file_path , true);
osw = new OutputStreamWriter(fos);
synchronized(osw){
osw.write( "[" + getTodayDate("2") + "]" + "\t" + log_content+ "\r\n" );
osw.flush();
}
} catch(Exception e){
e.printStackTrace();
} finally {
if(osw != null){
osw.close();
}
if(fos != null){
fos.close();
}
}
}
}
'Programing' 카테고리의 다른 글
Java encoding 강제로 (0) | 2010.11.30 |
---|---|
WinXP + Apache2.2.15 + Tomcat5.5 + J2SE1.5 + mod_jk연동 (2) | 2010.04.25 |
Tomcat NT버전 JAVA_PATH강제로 잡기 (0) | 2010.01.26 |
Apache,Tomcat mod_jk연동시 linsting 보이는 파일 처리 (0) | 2009.12.08 |
HTML index 포워딩 (1) | 2009.11.28 |