IO流-打印流 PrintStream

 1 package print.cn;
 2 
 3 import java.io.File;
 4 import java.io.FileNotFoundException;
 5 import java.io.FileOutputStream;
 6 import java.io.PrintStream;
 7 
 8 /*
 9  * 字节打印流 : 类 PrintStream
10  * 字符打印流:类 PrintWriter
11  * 类 PrintStream 构造方法:
12  * PrintWriter(OutputStream out) 
13           根据现有的 OutputStream 创建不带自动行刷新的新 PrintWriter。
14           主要方法:
15   void    print(boolean b) 
16           打印 boolean 值。
17   void    print(char c) 
18           打印字符。
19   void    print(char[] s) 
20           打印字符数组。
21   void    print(double d) 
22           打印 double 精度浮点数。
23   void    print(float f) 
24           打印一个浮点数。
25   void    print(int i) 
26           打印整数。
27   void    print(long l) 
28           打印 long 整数。
29   void    print(Object obj) 
30           打印对象。
31   void    print(String s) 
32           打印字符串。
33           
34        PrintWriter 相关操作详见api文档   
35  */
36 public class PrintDemo {
37     public static void main(String[] args) {
38         PrintStream ps =null;
39         try {
40              ps = new PrintStream(new FileOutputStream(new File("d:"+File.separator+"test2.txt")));
41         
42         } catch (FileNotFoundException e) {
43             // TODO Auto-generated catch block
44             e.printStackTrace();
45         }
46         ps.print("hello");
47         ps.println("world!!!");
48         ps.print("1+1 =22");
49     }
50 
51 }

 

posted @ 2017-06-05 14:03  初学者,方圆几里  阅读(132)  评论(0编辑  收藏  举报