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