[IO]——重定向

/**
 * 三個常量
 * system.in 輸入流 鍵盤輸入
 * system.out輸出流 控制檯輸出
 * system.err
 * ---》重定向
 * setin(),setout(),seterr()
 * filedescriptor.in   filedescriptor.out
 * @author Administrator
 *
 */
public class systemDemo {
	public static void main(String[] args) throws FileNotFoundException {
		//test2();
		//test1();
		//重定向
		System.setOut(new PrintStream(new BufferedOutputStream(new FileOutputStream("E:/others/qqqq.txt")),true));//自動刷新
		System.out.println("加油!");//控制檯--》文件
		//回控制檯
		System.setOut(new PrintStream(new BufferedOutputStream(new FileOutputStream(FileDescriptor.out)),true));//自動刷新
		System.out.println("come on !");
	}
	//從文件輸入
	public static void test2() throws FileNotFoundException{
		InputStream is=System.in;//鍵盤輸入
		is=new BufferedInputStream(new FileInputStream("E:/others/qqqq.txt"));
		Scanner sc=new Scanner(is);
		System.out.println("請輸入 :");
		System.out.println(sc.nextLine());
	}
	public static void test1(){
		System.out.println("中國");
		System.err.println("China");//打印錯誤信息
	
	}
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章