java.io.InputStream的read()和read(byte[] b)和read(byte[] b, int off, int len)有什么不同啊?什么时候用read()?什么时候用read(byte[] b),什么时候用read(byte[] b, int off, int len)啊?同问java.io.OutputStream的write(byte[] b)和write(byte[] b, int off, int len) 和te(int b)方法!
调试欢乐多
Reads the next byte of data from the input stream.
int read(byte[] b)
Reads some number of bytes from the input stream and stores them into the buffer array b.
int read(byte[] b, int off, int len)
Reads up to len bytes of data from the input stream into an array of bytes.
return read(b, 0, b.length);
}public void write(byte b[]) throws IOException {
write(b, 0, b.length);
}
read(byte[] b)将文本中的所有数据读取到b这个字节数组中
read(byte[] b, int off, int len)将文本中的所有数据读入到b字节数组的指定位置(这个貌似是这样
的,没有去测试)如楼上所说,这些都是可以在帮助文档里面查到的~
//从源码可以看出来,他们本来就是同一个东西
public int read(byte b[]) throws IOException {
return read(b, 0, b.length);
}public int read(byte b[], int off, int len) throws IOException {
if (b == null) {
throw new NullPointerException();
} else if (off < 0 || len < 0 || len > b.length - off) {
throw new IndexOutOfBoundsException();
} else if (len == 0) {
return 0;
} int c = read();
if (c == -1) {
return -1;
}
b[off] = (byte)c; int i = 1;
try {
for (; i < len ; i++) {
c = read();
if (c == -1) {
break;
}
b[off + i] = (byte)c;
}
} catch (IOException ee) {
}
return i;
}
public abstract int read() throws IOException;
read(byte[] b)将文本中的所有数据读取到b这个字节数组中
read(byte[] b, int off, int len)从流的第off个字节开始,读入长度为len的字节的数据--signature-------------------
http://www.mowker.com/view/