[Java 12 IO] OutputStream 字节输出流,继承自它的类,都是 程序中输出 数据

OutputStream 字节输出流,继承自它的类,都是 程序中输出 数据

OutputStreamDemo01

package com.qunar.basicJava.javase.io;

import java.io.*;

/**
 * Author: libin.chen@qunar.com  Date: 14-6-5 15:58
 */
public class OutputStreamDemo01 {
    public static void main(String[] args) throws IOException {
        // 第 1 步 : 使用 File 类找到一个文件
        File file = new File("/home/hp/tmp/test.txt");
        // 第 2 步 : 通过子类实例化父类对象
        OutputStream outputStream = new FileOutputStream(file);
        // 第 3 步 : 进行写操作
        String str = "Hello World!!!!!";
        byte b[] = str.getBytes();
        outputStream.write(b);
        // 第 4 步 : 关闭输出流
        //Thread.sleep(3000);
        outputStream.flush();
        outputStream.close();

    }
}

posted @ 2014-06-06 10:39  小尼人00  阅读(237)  评论(0编辑  收藏  举报