system.out.println 의 목적지를 화면이 아닌 파일로 저장하고자 할 때의 예제

/*

 * 문서번호: 20130411-1512

 * 검색어:  nabiro, java, println, system.out.println, 화면, 파일, 저장

 * 출처

 */

 

import java.io.*;

 

public class MyMainClass {

public static void main(String[] args) throws FileNotFoundException {

// TODO Auto-generated method stub

    //File file  = new File("/home/sajid/sysout.log");

    File file  = new File("c:\\sysout.log");

    PrintStream printStream = new PrintStream(new FileOutputStream(file));

 

    System.out.println("1"); // 화면으로 1 이라는 문자가 표시된다. 

   

    System.setOut(printStream);

   

    System.out.println("2"); // c:\sysout.log 파일로 2 라는 문자가 표시된다. 

  }

}

댓글

Designed by JB FACTORY