java中OutStremenr方法write偏移量是什么意思???

求解

public void write(byte[] b,
int off,
int len)
throws IOException将指定字节数组中从偏移量 off 开始的 len 个字节写入此输出流。write(b, off, len) 的常规协定是:将数组 b 中的某些字节按顺序写入输出流;元素 b[off] 是此操作写入的第一个字节,b[off+len-1] 是此操作写入的最后一个字节。
OutputStream 的 write 方法对每个要写出的字节调用一个参数的 write 方法。建议子类重写此方法并提供更有效的实现。

如果 b 为 null,则抛出 NullPointerException。

如果 off 为负,或 len 为负,或者 off+len 大于数组 b 的长度,则抛出 IndexOutOfBoundsException。

参数:
b - 数据。
off - 数据中的初始偏移量。
len - 要写入的字节数。
抛出:
IOException - 如果发生 I/O 错误。尤其是,如果关闭了输出流,则抛出 IOException。
温馨提示:答案为网友推荐,仅供参考
第1个回答  2019-08-21
write()参数,,第2个参数就是你说的偏移量。
第一个参数是写入的数据
第二个参数是从哪里开始写,一般都是0
第三个参数是写入多少个字节。
看我回答得简单易懂,你们写着一大堆搞得别人看不懂。
第2个回答  2012-03-30
偏移量参数是指从你传入buffer的那个位置开始写。

/**
* Writes {@code count} bytes from the byte array {@code buffer} starting at
* position {@code offset} to this stream.
*
* @param buffer
* the buffer to be written.
* @param offset
* the start position in {@code buffer} from where to get bytes.
* @param count
* the number of bytes from {@code buffer} to write to this
* stream.
* @throws IOException
* if an error occurs while writing to this stream.
* @throws IndexOutOfBoundsException
* if {@code offset < 0} or {@code count < 0}, or if
* {@code offset + count} is bigger than the length of
* {@code buffer}.
*/
public void write(byte[] buffer, int offset, int count) throws IOException {
相似回答