PrintIO 【013】


*****1.**********************************************************************

package Testioprint;
import java.io.* ;
public class Test1 {
	public static void main(String[] args) {
		PrintStream ps = null ;
		try {
			FileOutputStream fos = new FileOutputStream("d:\\java\\test7.txt") ;
			ps = new PrintStream(fos) ;
		} catch(FileNotFoundException e) {
			e.printStackTrace();
		}
		if(ps != null) {
			System.setOut(ps) ;
		}
		int i=0 ;
		for(char c=0; c<= 60000; c++) {
			System.out.print(c +" ") ;
			if(i ++>= 100) {
				System.out.println() ; //  
				i = 0 ; // i  
			}
		}

	}

}


*******2**************************************************************

package Testioprint;
import java.io.* ;
public class test2 {
	public static void main(String[] args) {
		String filename = args[0] ; //     
		if(filename != null) {
			list(filename, System.out) ;
		}
	}
	public static void list(String f, PrintStream fs) {
		try {
			BufferedReader br = new BufferedReader(new FileReader(f)) ;
			String s = null ;
			while((s=br.readLine())!= null) {
				fs.println(s) ;
			}
			br.close() ;
		} catch (IOException e) {
			fs.println("read file error") ;
		}
	}

}

*****3*******************************************************************

package Testioprint;
import java.io.*;
import java.util.* ;
public class test3 {
	public static void main(String []args) {
		int year,month,day ;
		year = Calendar.getInstance().get(Calendar.YEAR) ;
		month = Calendar.getInstance().get(Calendar.MONTH) ;
		day = Calendar.getInstance().get(Calendar.DATE) ;
		String s = null ;
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in)) ;
		try {
			PrintWriter pw = new PrintWriter(new FileWriter("d:/java/tests.txt",true)) ;
			while ((s=br.readLine()) != null) {
				if(s.equalsIgnoreCase("exit"))
					break ;
				System.out.println(s.toUpperCase()) ;  //         
				pw.println(s.toUpperCase()) ;  //   String s
				pw.println("------------") ;
				pw.flush();
			}
			pw.println("==      :"+ year+" -"+ month +"- -"+ day +"- "+ "==" ) ;
			pw.println() ;
			pw.flush();
			pw.close();
		} catch(IOException e) {
			e.printStackTrace();
		}
	}

}