类的定义结构字节数出流OUtPutStraem有两个接口outPutStream{abstract}closeable《Interface》 close
Flushable《Interface 》 flushautocloseable可以发现OutPutStream类中实现了Closeable Flushable 两个接口,跑出IOexception接口比问题出现的晚。内部含有close 和flush方法。write 方法时关键public void write(byte[] b) 将给定的字节数组内容全部输出 public void write(byte[] b,int offset int length) 将部分字节输出 public abstruct void write(int b)throws Exception 抽象方法,输出单个字节outputsream 是一个抽象类,如果想要父类实例化,那么就要使用子类实例化。此处所关注的只关注子类的构造方法,可以使用FileOutput Stream 的类中的方法。接收File类 public FileOutputStream(File file,Boolean append )throws FileNotfoudException 追加,append 为true 时,表示追加关于输出的异常抛出 output.write(str.getBytes(),1,1) 最常用的输出语句
实现文件内容的输出
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;public class TestDemo{
public static void main(String[] args) throws Exception{
File file=