java使用IO打印流输出到文件

来源:互联网 发布:蒙特卡洛算法 编辑:程序博客网 时间:2024/06/07 06:37

打印流(只有输出流、没有输入流)

打印流小例子

package com.uwo9.test01;import java.io.File;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.OutputStream;import java.io.PrintStream;public class Test08 {public static void main(String[] args) {File toFile = new File("E:/Temp/Test1.txt");PrintStream ps = null;OutputStream os = null;try {// ps = new PrintStream(toFile);//可直接传Fileos = new FileOutputStream(toFile, true);//true在原文件上追加ps = new PrintStream(os, true);//true自动刷新ps.println(10);ps.println("HelloWorld");} catch (FileNotFoundException e) {e.printStackTrace();} finally {ps.close();}}}




原创粉丝点击