易学笔记-0:Java语言总结/0.11 Java中输出的流表示(都是针对字节数组byte[ ]操作)

  • Java中输出的流表示
  1. 针对缓存的:
    1. ByteArrayOutputStream
    2. StringBufferOutputStream
  2. 针对文件的:FileOutputStream
  3. 针对对象:ObjectOutputStream
  4. 针对线程的:PipedOutputStream
  5. 针对过滤器:FilterOutputtream
    1. DataOutputStream
    2. BufferedOutputStream
  6. 超级基类:OutputStream:public abstract class OutputStream implements Closeable, Flushable
    1. 写入:
      1. public abstract void write(int b) throws IOException;
      2. public void write(byte b[]) throws IOException
      3. public void write(byte b[], int off, int len) throws IOException
    2. 可替换:public void flush() throws IOException
    3. 可拷贝:public void close() throws IOException
  7. 字节数组输出流:ByteArrayOutputStream
    1. 数据结构
      1. protected byte buf[];
      2. protected int count;
    2. 方法
      1. public synchronized void write(int b)
      2. public synchronized void write(byte b[], int off, int len)
      3. public synchronized void writeTo(OutputStream out) throws IOException
      4. public synchronized byte toByteArray()[]
      5. public synchronized int size()
  8. 文件输出流:FileOutputStream
    1. public FileOutputStream(String name) throws FileNotFoundException
    2. public FileOutputStream(String name, boolean append)
    3. public FileOutputStream(File file) throws FileNotFoundException
    4. public FileOutputStream(File file, boolean append)
    5. public FileOutputStream(FileDescriptor fdObj)
    6. public void write(int b) throws IOException
    7. public void write(byte b[]) throws IOException
    8. public void write(byte b[], int off, int len) throws IOException
    9. public void close() throws IOException
    10. public final FileDescriptor getFD()  throws IOException
    11. public FileChannel getChannel()
  9. 管道输出流:PipedOutputStream
  10. 过滤输出流:FilterOutputStream
    1. 数据成员
      1.  protected OutputStream out;
    2. 方法:通过out调用相关的方法,构造方法就是接受外面的输入对象,比如:ByteArrayOutputStream 、FileOutputStream 、PipedOutputStream 等,实际上调用的就是传进来的对象
  11. DataOutPutStream:适应各种数据类型的输出
    1. 超级基类:DataOutput:接口用于将数据从任意 Java 基本类型转换为一系列字节,并将这些字节写入二进制流。同时还提供了一个将 String 转换成 UTF-8 修改版格式并写入所得到的系列字节的工具
      1. 写入整型:void write(int b) throws IOException;
      2. 写入字节数组:void write(byte b[]) throws IOException;
      3. 写入字节数组:void write(byte b[], int off, int len) throws IOException;
      4. 写入布尔:void writeBoolean(boolean v) throws IOException;
      5. 写入字节:void writeByte(int v) throws IOException;
      6. 写入短整型:void writeShort(int v) throws IOException;
      7. 写入字符:void writeChar(int v) throws IOException;
      8. 写入整型:void writeInt(int v) throws IOException;
      9. 写入长整型:void writeLong(long v) throws IOException;
      10. 写入浮点:void writeFloat(float v) throws IOException;
      11. 写入浮点:void writeDouble(double v) throws IOException;
      12. 写入字节流:void writeBytes(String s) throws IOException;
      13. 写入字符流:void writeChars(String s) throws IOException;
      14. 写入UTF:void writeUTF(String s) throws IOException;!
    2. DataOutputStream:实现 DataOutput 各个方法
      1. output的类型与input的类型要一致,也就是writeDouble与readDouble要一致,writeUTF与readUTF要一致
      2. 为了避免出现写入和读取类型问题,建议output采用统一的类型writeUTF,input时采用readUTF
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

易学笔记(qq:1776565180)

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值