Is there an easy way to write OutputStream with InputStream? It's not hard to write to the byte buffer code, but I think I'm missing an easier way...
If InputStream has in and OutputStream has out
byte[] buffer = new byte[1024];
int len = in.read(buffer);
while (len != -1) {
out.write(buffer, 0, len);
len = in.read(buffer);
}
Is there any easier code than this?
java io stream
The Apache Common library has a class called IOUtils. You can do it easily by using the method called copy in this class.
InputStream in;
OutputStream out;
IOUtils.copy(in,out);
in.close();
out.close();
You can do it like this.
© 2024 OneMinuteCode. All rights reserved.