캠핑과 개발

java에서 파일에 추가 라인을 입력하고 싶을때 옵션입니다. 15라인 참고하면 됩니다.

  1. package kr.pe.anaconda.test;
  2.  
  3. import java.io.FileNotFoundException;
  4. import java.io.FileWriter;
  5. import java.io.IOException;
  6. import java.io.PrintWriter;
  7.  
  8. public class Test {
  9.  
  10.     public static void main(String[] args) {       
  11.        
  12.         String file = "C:/logs/log.log";
  13.         PrintWriter pw = null;
  14.         try {
  15.             pw = new PrintWriter(new FileWriter(file, true));
  16.             pw.write(String.valueOf(System.currentTimeMillis()));
  17.             pw.write("\n");
  18.         } catch (FileNotFoundException e) {        
  19.             e.printStackTrace();
  20.         } catch (IOException e) {          
  21.             e.printStackTrace();
  22.         }finally{
  23.             if(pw != null) pw.close();
  24.         }
  25.     }
  26. }