File---PrintStream印刷ストリーム

2168 ワード


 
 
/**
 * PrintStream   --> 
 * @author Administrator
 *
 */
public class PrintStreamDemo01 {

	/**
	 * @param args
	 * @throws FileNotFoundException 
	 */
	public static void main(String[] args) throws FileNotFoundException {
		System.out.println("test");
		PrintStream ps =System.out;
		ps.println(false);
		
		
		// 
		File src = new File("e:/xp/test/print.txt");
		ps = new PrintStream(new BufferedOutputStream(new FileOutputStream(src)));
		ps.println("io is so easy....");
		
		ps.close();
	}

}

 
 
 
/**
 *  
 * 1、System.in      
 * 2、System.out      
 *    System.err
 *    
 * ==>    
 * setIn()
 * setOut()
 * setErr()
 * FileDescriptor.in
 * FileDescriptor.out
 * @author Administrator
 *
 */
public class SystemDemo01 {

	/**
	 * @param args
	 * @throws FileNotFoundException 
	 */
	public static void main(String[] args) throws FileNotFoundException {
		//test1();
		//test2();
		// 
		System.setOut(new PrintStream(new BufferedOutputStream(new FileOutputStream("e:/xp/test/print.txt")),true));
		System.out.println("a");  //   --> 		
		System.out.println("test");
		// 
		System.setOut(new PrintStream(new BufferedOutputStream(new FileOutputStream(FileDescriptor.out)),true));
		System.out.println("back....");
	}
	public static void test2() throws FileNotFoundException{
		InputStream is =System.in;  // 
		is = new BufferedInputStream(new FileInputStream("e:/xp/test/print.txt"));
		Scanner sc = new Scanner(is);
		//System.out.println(" :");
		System.out.println(sc.nextLine());
	}
	
	public static void test1(){
		System.out.println("test");
		System.err.println("err");
	}

}