package transit;
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;
/**
* setErr()
* setIn()
* setOut()
*重定向
* FileDescriptor.out
* FileDescriptor.in
* @author Lenovo
*
*/
public class PrintStrem {
public static void main(String[] args) throws FileNotFoundException{
//重定向
System.setOut(new PrintStream(
new BufferedOutputStream(new FileOutputStream(new File("G:/filetext/text"),true))));
System.out.println("给理性划清界限,为自由和道德留下空间。");//被输向了--->文件
//重行转回控制台
System.setOut(new PrintStream(new BufferedOutputStream(new FileOutputStream(FileDescriptor.out)), true));
System.out.println("给理性划清界限,为自由和道德留下空间。");
}
/**
* PrintStream打印流,也是输出流--->处理流
* @throws FileNotFoundException
*/
public static void input() throws FileNotFoundException {
PrintStream io=new PrintStream(
new BufferedOutputStream(new FileOutputStream(new File("G:/filetext/text"))));
io.println("每一个不曾起舞的日子,都是对生命的辜负");
io.close();
}
public static void sysout() throws FileNotFoundException {
InputStream is=new BufferedInputStream(new FileInputStream(new File("G:/filetext/text")));
Scanner scanner =new Scanner(is);
System.out.println(scanner.nextLine());
}
}