Copies the contents of the Reader into the Writer, until the end of the stream has been reached. : Copy « File « Java Tutorial






import java.io.IOException;
import java.io.Reader;
import java.io.Writer;

/* 
 * JCommon : a free general purpose class library for the Java(tm) platform
 * 
 *
 * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
 * 
 * Project Info:  http://www.jfree.org/jcommon/index.html
 *
 * This library is free software; you can redistribute it and/or modify it 
 * under the terms of the GNU Lesser General Public License as published by 
 * the Free Software Foundation; either version 2.1 of the License, or 
 * (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but 
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 
 * License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
 * USA.  
 *
 * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 
 * in the United States and other countries.]
 * 
 * ------------
 * IOUtils.java
 * ------------
 * (C)opyright 2002-2004, by Thomas Morgner and Contributors.
 *
 * Original Author:  Thomas Morgner;
 * Contributor(s):   David Gilbert (for Object Refinery Limited);
 *
 * $Id: IOUtils.java,v 1.8 2009/01/22 08:34:58 taqua Exp $
 *
 * Changes
 * -------
 * 26-Jan-2003 : Initial version
 * 23-Feb-2003 : Documentation
 * 25-Feb-2003 : Fixed Checkstyle issues (DG);
 * 29-Apr-2003 : Moved to jcommon
 * 04-Jan-2004 : Fixed JDK 1.2.2 issues with createRelativeURL;
 *               added support for query strings within these urls (TM);
 */


/**
 * The IOUtils provide some IO related helper methods.
 *
 * @author Thomas Morgner.
 */
public class Main {
  /**
   * Copies the contents of the Reader into the Writer, until the end of the 
   * stream has been reached.
   *
   * @param in  the reader from which to read.
   * @param out  the writer where the data is written to.
   * @param buffersize  the buffer size.
   *
   * @throws IOException if a IOError occurs.
   */
  public void copyWriter(final Reader in, final Writer out, 
          final int buffersize)
      throws IOException {
      // create a 4kbyte buffer to read the file
      final char[] bytes = new char[buffersize];

      // the input stream does not supply accurate available() data
      // the zip entry does not know the size of the data
      int bytesRead = in.read(bytes);
      while (bytesRead > -1) {
          out.write(bytes, 0, bytesRead);
          bytesRead = in.read(bytes);
      }
  }
}








11.78.Copy
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