OutputStream 及子类

来源:互联网 发布:java 异常类 课件 编辑:程序博客网 时间:2024/05/20 06:52
  • 该抽象类是所有类的字节输出流的父类。输出流接受输出字节,并将它们发送到一些接收器。

    这需要定义一个类OutputStream应用必须至少提供一个方法将输出一个字节

  • 直接子类有FileOutputStream,OutputStream等

方法:
close()
关闭此输出流并释放与此流关联的任何系统资源。

flush()
刷新输出流,使缓存数据被写出来。

write(byte[] b)
b.length字节从指定的字节数组的输出流。 

write(byte[] b, int off, int len)
len字节指定字节数组中的偏移 off开始到输出流。


  • public class FileOutputStreamextends OutputStream

  • 文件输出流是一个 File或一个 FileDescriptor数据写入输出流

  • public FileOutputStream(String name)                 throws FileNotFoundException
    创建一个文件输出流,用指定的名称写入文件

  • public FileOutputStream(String name,                        boolean append)                 throws FileNotFoundException
    创建一个文件输出流,用指定的名称写入文件。如果第二 true,然后字节将被写入到文件的末尾而不是开头
  • public FileOutputStream(File file)                 throws FileNotFoundException
    创建一个文件输出流写入指定的 File对象表示的文件
  • public FileOutputStream(File file,                        boolean append)                 throws FileNotFoundException
    创建一个文件输出流写入指定的 File对象表示的文件。如果第二 true,然后字节将被写入到文件的末尾而不是开头。
  • public void write(int b)           throws IOException
    将指定的字节写入该文件输出流中。实现的方法 OutputStream write。 
  • public void write(byte[] b)           throws IOException
    b.length字节从指定的字节数组来此文件输出流。 
  • public void write(byte[] b,                  int off,                  int len)           throws IOException
    len字节指定字节数组中的起始偏移 off此文件输出流。 
  • public void close()           throws IOException
    关闭此文件输出流并释放与此流关联的任何系统资源。此文件输出流可能不再用于写入字节
  • protected void finalize()                 throws IOException
    清理文件的连接,并确保此文件输出流的 close方法被调用时,没有引用此流。