1 import java.io.FileNotFoundException; 2 import java.io.FileOutputStream; 3 import java.io.PrintStream; 4 /** 5 * printIO流 6 * @author 罗摩衔那 7 * 8 */ 9 public class TestPrintStream { 10 public static void main(String[] args) { 11 PrintStream ps=null; 12 try {//输出的目的文件 13 FileOutputStream fos = 14 new FileOutputStream("D:/罗摩衔那/DeskTop/write.txt"); 15 ps=new PrintStream(fos); 16 } catch (FileNotFoundException e) { 17 e.printStackTrace(); 18 } 19 if(ps !=null) 20 { 21 System.out.println(ps); 22 } 23 int in=0; 24 for(char c=0;c<=60000;c++) 25 { 26 System.out.println(c+" "); 27 if(in++>=100) {System.out.println();in=in-0;} 28 } 29 } 30 }
1 import java.io.BufferedReader; 2 import java.io.FileNotFoundException; 3 import java.io.FileReader; 4 import java.io.IOException; 5 import java.io.PrintStream; 6 /** 7 * printIO流 8 * @author 罗摩衔那 9 * 10 */ 11 public class TestPrintStream2 { 12 public static void main(String[] args) { 13 //传入命令行参数 14 String filename=args[0]; 15 if(filename!=null) {list(filename,System.out);} 16 } 17 18 public static void list(String filename, PrintStream out) { 19 try { 20 BufferedReader br= 21 new BufferedReader(new FileReader(filename)); 22 String s=null; 23 while((s=br.readLine())!=null) { 24 out.println(s); 25 } 26 br.close(); 27 } catch (IOException e) { 28 29 out.println("无法读取文件"); 30 } 31 } 32 }
1 import java.io.BufferedReader; 2 import java.io.FileWriter; 3 import java.io.IOException; 4 import java.io.InputStreamReader; 5 import java.io.PrintWriter; 6 import java.util.Date; 7 /** 8 * printIO流 9 * @author 罗摩衔那 10 * 11 */ 12 public class TestPrintStream3 { 13 public static void main(String[] args) { 14 String s=null; 15 //确定输入源为键盘录入 16 BufferedReader br=new BufferedReader( 17 new InputStreamReader(System.in)); 18 try {//输出目的文件 19 FileWriter fw=new FileWriter 20 ("d:/罗摩衔那/DeskTop/PrintStream.txt",true); 21 PrintWriter log=new PrintWriter(fw); 22 while((s=br.readLine())!=null)//读取一行 23 { 24 if(s.equalsIgnoreCase("exit")) break;//退出循环条件 25 System.out.println(s.toUpperCase());//读取到的字母转换为大写 26 log.println("------------"); 27 log.print(s.toUpperCase());//信息写入文件中 28 log.flush();//实时写入 29 } 30 log.println("==="+new Date()+"==="); 31 log.flush(); 32 log.close(); 33 } 34 catch (IOException e) { 35 36 e.printStackTrace(); 37 } 38 } 39 }