zoukankan      html  css  js  c++  java
  • Java打印流学习

    打印流

    打印流的主要功能是用于输出,在整个IO包打印流分为两种类型,打印流可以很方便的进行输出。

    1、字节打印流:PrintStream(在字节输出时,可以增强输出功能)

    2、字符打印流:PrintWriter

    import java.io.BufferedOutputStream;
    import java.io.BufferedWriter;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.io.OutputStream;
    import java.io.PrintStream;
    import java.io.PrintWriter;
    import java.io.Writer;
    
    
    public class PrintStreamDemo {
    
    	// 字节打印流,向文件中写入数据
    	private static void bytePrint() {
    		File file = new File("F:/test.txt");
    		try {
    			OutputStream out = new FileOutputStream(file, true);
    			// 加缓冲流
    			BufferedOutputStream bos = new BufferedOutputStream(out);
    			// 增强打印功能
    			PrintStream ps = new PrintStream(bos);
    			ps.println("字节打印流很方便。。。");
    
    			System.out.println("写入完毕");
    			ps.close();
    		} catch (FileNotFoundException e) {
    			e.printStackTrace();
    		}
    	}// bytePrint
    
    	// 字符打印流,向文件中写入数据
    	private static void charPrint() {
    		File file = new File("F:/test.txt");
    		try {
    			Writer writer = new FileWriter(file, true);
    			// 加缓冲流
    			BufferedWriter bw = new BufferedWriter(writer);
    			// 增强打印功能
    			PrintWriter pw = new PrintWriter(bw);
    			pw.println("字符打印流很方便。。。");
    
    			System.out.println("写入完毕");
    			pw.close();
    		} catch (FileNotFoundException e) {
    			e.printStackTrace();
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    	}// charPrint
    
    }
  • 相关阅读:
    fill 全解(转)
    解题报告 疯狂的馒头
    解题报告 报数
    解题报告 noi 2005 智慧珠游戏(BT 搜索)
    解题报告 跑步
    解题报告 Punch
    解题报告 纪念日
    解题报告 新兵站队
    转载:让理科生沉默,让文科生流泪的综合题
    解题报告 信号放大器
  • 原文地址:https://www.cnblogs.com/zxfei/p/10874912.html
Copyright © 2011-2022 走看看