Java 10 中的 java.io.Reader transferTo(java.io.Writer) 方法是什么? InputStream有没有类似的方法?
What is java.io.Reader transferTo(java.io.Writer) method in Java 10 ? Is there a similar method for InputStream?
我读了 Java 10 documentation on java.io.Reader.transferTo(...)
上面写着:
Reads all characters from this reader and writes the characters to the
given writer in the order that they are read
Reader
中的方法 transferTo
将非常有用,因为目前将数据从 reader 复制到 writer 非常冗长。由于我们在实际应用中主要使用InputStream
和OutputStream
,是否有类似的方法?
自从Java 9: InputStream.transferTo()
InputStream
中就有这样的方法
此外,对于 JDK 的早期版本,有 IOUtils.copy(InputStream input, OutputStream output)
in apache-commons-io 库。
文档说:
Copies bytes from an InputStream to an OutputStream
所以,它应该做同样的事情。
我读了 Java 10 documentation on java.io.Reader.transferTo(...)
上面写着:
Reads all characters from this reader and writes the characters to the given writer in the order that they are read
Reader
中的方法 transferTo
将非常有用,因为目前将数据从 reader 复制到 writer 非常冗长。由于我们在实际应用中主要使用InputStream
和OutputStream
,是否有类似的方法?
自从Java 9: InputStream.transferTo()
InputStream
中就有这样的方法
此外,对于 JDK 的早期版本,有 IOUtils.copy(InputStream input, OutputStream output)
in apache-commons-io 库。
文档说:
Copies bytes from an InputStream to an OutputStream
所以,它应该做同样的事情。