Copy chars from a Reader to a Writer. : Copy « File « Java Tutorial


public class Main {
   * Copy chars from a <code>Reader</code> to a <code>Writer</code>.
   * This method buffers the input internally, so there is no need to use a
   * <code>BufferedReader</code>.
   * @param input
   *          the <code>Reader</code> to read from
   * @param output
   *          the <code>Writer</code> to write to
   * @return the number of characters copied
   * @throws NullPointerException
   *           if the input or output is null
   * @throws IOException
   *           if an I/O error occurs
   * @since 1.1
  public static int copy(Reader input, Writer output) throws IOException {
    char[] buffer = new char[1024];
    int count = 0;
    int n = 0;
    while (-1 != (n = {
      output.write(buffer, 0, n);
      count += n;
    return count;

11.78.1.Copy the source file system structure into the supplied target location.
11.78.2.Buffered copying between source(InputStream, Reader, String and byte[]) and destinations (OutputStream, Writer, String and byte[]).
11.78.3.Copies all data from an input stream to an output stream.
11.78.4.Copies the contents of the Reader into the Writer, until the end of the stream has been reached.
11.78.5.Copy a directory and all of its contents.
11.78.6.Copy a file and user buffer
11.78.7.Copy chars from a Reader to a Writer.
11.78.8.copy Completely (InputStream input, OutputStream output)
11.78.9.copy Completely (Reader input, Writer output)
11.78.10.copy Completely(URI input, URI output)
11.78.11.Buffered copying
11.78.12.Copy file and directory