자바 에서 파일 로 출력
1318 단어 JavaSE 노트
package tk.javazhangwei.others;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;
/***
* 1.system.in
* 2.system.ou
* system.err
*
* @author zw
*
*/
public class SystemDemo01 {
public static void main(String[] args) throws FileNotFoundException {
//
//
System.setOut(new PrintStream(new BufferedOutputStream(
new FileOutputStream("d:/test/print.txt")),true));
// true flush
System.out.println("bbb");//
//
System.setOut(new PrintStream(new BufferedOutputStream(
new FileOutputStream(FileDescriptor.out)),true));
System.out.println("Hello,World!");
}
//
public static void test2() throws FileNotFoundException {
InputStream is =System.in;
is = new BufferedInputStream(new FileInputStream(new File("D:/test/print.txt")));
Scanner sc = new Scanner(is);
System.out.println(sc.nextLine());
}
//
public static void test1() {
System.out.println("hello");
System.err.println(" ");
}
}