【发布时间】:2017-09-11 11:39:29
【问题描述】:
我目前正在学习 Java IO 函数和编码,但在阅读在线教程时有点困惑。这是参考此处发布的问题:InputStream/OutputStream read()/write() function relevance and usage
这似乎暗示了基本 write() 函数和 write(byte[] bytes, int offset, int length) 函数的时间效率很高,但我不太明白它的意思。
在教程中是这样说的:
public int read(byte[] bytes, int offset, int length) throws IOException
// Read "length" number of bytes, store in bytes array starting from offset
of index.
public int read(byte[] bytes) throws IOException
// Same as read(bytes, 0, bytes.length)
这两行代码究竟做了什么来说明 read() 在 java IO 中的作用?第一行也是读取文件信息的长度或文件的实际信息本身。
为了更加混乱,OutputStream 的 Write() 函数解释如下:
“类似于输入对应,抽象超类 OutputStream 声明了一个抽象方法 write() 将数据字节写入输出接收器。write() 接受一个 int。写入 int 参数的最低有效字节out; 高 3 个字节被丢弃。如果发生 I/O 错误(例如,输出流已关闭),则抛出 IOException。"
这是否意味着实际信息或参数被写入?有点混淆了该段落想要表达的意思。
public void abstract void write(int unsignedByte) throws IOException\
public void write(byte[] bytes, int offset, int length) throws IOException
// Write "length" number of bytes, from the bytes array starting from offset
of index.
public void write(byte[] bytes) throws IOException
// Same as write(bytes, 0, bytes.length)
提前感谢您对此的任何解释。
【问题讨论】:
-
“写入的实际信息或参数”到底是什么意思?
标签: java