代码拉取完成,页面将自动刷新
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);
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。