当前位置: 代码迷 >> 综合 >> [Java 12 IO] OutputStream 字节输出流,继承自它的类,都是 程序中输出 数据
  详细解决方案

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

热度:56   发布时间:2023-12-14 08:43:20.0

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();}
}

  相关解决方案