OutputStream 输出流

OutputStream是个抽象类,它的作用是往输出流中写入字节。

OutputStream 方法介绍

OutputStream的方法有两个:

方法1:写入int类型的数据

public abstract void write(int b) throws IOException;

JDK说明: Writes the specified byte to this output stream. The general contract for write is that one byte is written to the output stream. The byte to be written is the eight low-order bits of the argument b. The 24 high-order bits of b are ignored.

需要注意的是:这个函数并不是把int类型的b写入输出流,而是仅仅截取b的低位8 bit。其他的24 bit 则忽略掉。

方法2:写入字节类型的数据

public void write(byte b[]) throws IOException {
    write(b, 0, b.length);
}

此方法没有任何截断,直接将字节数组b都写入了输出流中。

标签: none

[网站公告]-[2024年兼职介绍]


添加新评论