java 文件字节输出流
Example10_5.java
import java.io.*; public class Example10_5 { public static void main(String args[]) { byte [] a = "新年快乐".getBytes(); byte [] b = "Happy New Year".getBytes(); File file = new File("a.txt"); //输出的目的地 try{ OutputStream out=new FileOutputStream(file); //指向目的地的输出流 System.out.println(file.getName()+"的大小:"+file.length()+"字节");//a.txt的大小:0字节 out.write(a); //向目的地写数据 out.close(); out=new FileOutputStream(file,true); //准备向文件尾加内容 System.out.println(file.getName()+"的大小:"+file.length()+"字节");///a.txt的大小:8字节 out.write(b,0,b.length); System.out.println(file.getName()+"的大小:"+file.length()+"字节");///a.txt的大小:8字节 out.close(); } catch(IOException e) { System.out.println("Error "+e); } } }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了