企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
```java package com.gosuncn; import java.io.FileOutputStream; import java.io.IOException; public class JavaIOOutputStream { public static final String DESTINATION_FILENAME = "C:\\Users\\Administrator\\Desktop\\UTF8.txt"; public static void main(String[] args) throws Exception { flush(new FileOutputStream(DESTINATION_FILENAME)); } public static void write1(FileOutputStream outputStream) throws IOException { /** * 默认写入int低八位的一字节数据. * 如果文件不存在,则默认是创建新文件. * 如果文件存在,则默认是删除原文件,创建新文件. */ outputStream.write(97); } public static void write2(FileOutputStream outputStream) throws IOException { byte[] data = new byte[3]; data[0] = 97; data[1] = 98; data[2] = 99; outputStream.write(data); // 写入字节数组 } public static void write3(FileOutputStream outputStream) throws IOException { byte[] data = new byte[3]; data[0] = 97; data[1] = 98; data[2] = 99; /** * off 偏移data的off字节数 * len 写入len个字节 */ outputStream.write(data, 1, 1); } public static void flush(FileOutputStream outputStream) throws IOException { outputStream.write(97); outputStream.flush(); // 将缓冲区的内容刷到磁盘 } } ```