Copying Input Stream to Output Stream
suggest changeThis method copies data from one stream to another:
void copy(InputStream in, OutputStream out) throws IOException {
byte[] buffer = new byte[8192];
int bytesRead;
while ((bytesRead = in.read(buffer)) != -1) {
out.write(buffer, 0, bytesRead);
}
}
Example -
// reading from System.in and writing to System.out
copy(System.in, System.out);
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents