Home » openjdk-7 » java » io » [javadoc | source]

    1   /*
    2    * Copyright (c) 1996, 2001, Oracle and/or its affiliates. All rights reserved.
    3    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    4    *
    5    * This code is free software; you can redistribute it and/or modify it
    6    * under the terms of the GNU General Public License version 2 only, as
    7    * published by the Free Software Foundation.  Oracle designates this
    8    * particular file as subject to the "Classpath" exception as provided
    9    * by Oracle in the LICENSE file that accompanied this code.
   10    *
   11    * This code is distributed in the hope that it will be useful, but WITHOUT
   12    * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   13    * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   14    * version 2 for more details (a copy is included in the LICENSE file that
   15    * accompanied this code).
   16    *
   17    * You should have received a copy of the GNU General Public License version
   18    * 2 along with this work; if not, write to the Free Software Foundation,
   19    * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   20    *
   21    * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   22    * or visit www.oracle.com if you need additional information or have any
   23    * questions.
   24    */
   25   
   26   package java.io;
   27   
   28   
   29   /**
   30    * Convenience class for writing character files.  The constructors of this
   31    * class assume that the default character encoding and the default byte-buffer
   32    * size are acceptable.  To specify these values yourself, construct an
   33    * OutputStreamWriter on a FileOutputStream.
   34    *
   35    * <p>Whether or not a file is available or may be created depends upon the
   36    * underlying platform.  Some platforms, in particular, allow a file to be
   37    * opened for writing by only one <tt>FileWriter</tt> (or other file-writing
   38    * object) at a time.  In such situations the constructors in this class
   39    * will fail if the file involved is already open.
   40    *
   41    * <p><code>FileWriter</code> is meant for writing streams of characters.
   42    * For writing streams of raw bytes, consider using a
   43    * <code>FileOutputStream</code>.
   44    *
   45    * @see OutputStreamWriter
   46    * @see FileOutputStream
   47    *
   48    * @author      Mark Reinhold
   49    * @since       JDK1.1
   50    */
   51   
   52   public class FileWriter extends OutputStreamWriter {
   53   
   54       /**
   55        * Constructs a FileWriter object given a file name.
   56        *
   57        * @param fileName  String The system-dependent filename.
   58        * @throws IOException  if the named file exists but is a directory rather
   59        *                  than a regular file, does not exist but cannot be
   60        *                  created, or cannot be opened for any other reason
   61        */
   62       public FileWriter(String fileName) throws IOException {
   63           super(new FileOutputStream(fileName));
   64       }
   65   
   66       /**
   67        * Constructs a FileWriter object given a file name with a boolean
   68        * indicating whether or not to append the data written.
   69        *
   70        * @param fileName  String The system-dependent filename.
   71        * @param append    boolean if <code>true</code>, then data will be written
   72        *                  to the end of the file rather than the beginning.
   73        * @throws IOException  if the named file exists but is a directory rather
   74        *                  than a regular file, does not exist but cannot be
   75        *                  created, or cannot be opened for any other reason
   76        */
   77       public FileWriter(String fileName, boolean append) throws IOException {
   78           super(new FileOutputStream(fileName, append));
   79       }
   80   
   81       /**
   82        * Constructs a FileWriter object given a File object.
   83        *
   84        * @param file  a File object to write to.
   85        * @throws IOException  if the file exists but is a directory rather than
   86        *                  a regular file, does not exist but cannot be created,
   87        *                  or cannot be opened for any other reason
   88        */
   89       public FileWriter(File file) throws IOException {
   90           super(new FileOutputStream(file));
   91       }
   92   
   93       /**
   94        * Constructs a FileWriter object given a File object. If the second
   95        * argument is <code>true</code>, then bytes will be written to the end
   96        * of the file rather than the beginning.
   97        *
   98        * @param file  a File object to write to
   99        * @param     append    if <code>true</code>, then bytes will be written
  100        *                      to the end of the file rather than the beginning
  101        * @throws IOException  if the file exists but is a directory rather than
  102        *                  a regular file, does not exist but cannot be created,
  103        *                  or cannot be opened for any other reason
  104        * @since 1.4
  105        */
  106       public FileWriter(File file, boolean append) throws IOException {
  107           super(new FileOutputStream(file, append));
  108       }
  109   
  110       /**
  111        * Constructs a FileWriter object associated with a file descriptor.
  112        *
  113        * @param fd  FileDescriptor object to write to.
  114        */
  115       public FileWriter(FileDescriptor fd) {
  116           super(new FileOutputStream(fd));
  117       }
  118   
  119   }

Home » openjdk-7 » java » io » [javadoc | source]