Copying Input Stream to Output Stream

suggest change

This 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);

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents