1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/rt/emul/compact/src/main/java/java/io/FileWriter.java Thu Oct 03 15:40:35 2013 +0200
1.3 @@ -0,0 +1,119 @@
1.4 +/*
1.5 + * Copyright (c) 1996, 2001, Oracle and/or its affiliates. All rights reserved.
1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1.7 + *
1.8 + * This code is free software; you can redistribute it and/or modify it
1.9 + * under the terms of the GNU General Public License version 2 only, as
1.10 + * published by the Free Software Foundation. Oracle designates this
1.11 + * particular file as subject to the "Classpath" exception as provided
1.12 + * by Oracle in the LICENSE file that accompanied this code.
1.13 + *
1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1.17 + * version 2 for more details (a copy is included in the LICENSE file that
1.18 + * accompanied this code).
1.19 + *
1.20 + * You should have received a copy of the GNU General Public License version
1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1.23 + *
1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1.25 + * or visit www.oracle.com if you need additional information or have any
1.26 + * questions.
1.27 + */
1.28 +
1.29 +package java.io;
1.30 +
1.31 +
1.32 +/**
1.33 + * Convenience class for writing character files. The constructors of this
1.34 + * class assume that the default character encoding and the default byte-buffer
1.35 + * size are acceptable. To specify these values yourself, construct an
1.36 + * OutputStreamWriter on a FileOutputStream.
1.37 + *
1.38 + * <p>Whether or not a file is available or may be created depends upon the
1.39 + * underlying platform. Some platforms, in particular, allow a file to be
1.40 + * opened for writing by only one <tt>FileWriter</tt> (or other file-writing
1.41 + * object) at a time. In such situations the constructors in this class
1.42 + * will fail if the file involved is already open.
1.43 + *
1.44 + * <p><code>FileWriter</code> is meant for writing streams of characters.
1.45 + * For writing streams of raw bytes, consider using a
1.46 + * <code>FileOutputStream</code>.
1.47 + *
1.48 + * @see OutputStreamWriter
1.49 + * @see FileOutputStream
1.50 + *
1.51 + * @author Mark Reinhold
1.52 + * @since JDK1.1
1.53 + */
1.54 +
1.55 +public class FileWriter extends OutputStreamWriter {
1.56 +
1.57 + /**
1.58 + * Constructs a FileWriter object given a file name.
1.59 + *
1.60 + * @param fileName String The system-dependent filename.
1.61 + * @throws IOException if the named file exists but is a directory rather
1.62 + * than a regular file, does not exist but cannot be
1.63 + * created, or cannot be opened for any other reason
1.64 + */
1.65 + public FileWriter(String fileName) throws IOException {
1.66 + super(new FileOutputStream(fileName));
1.67 + }
1.68 +
1.69 + /**
1.70 + * Constructs a FileWriter object given a file name with a boolean
1.71 + * indicating whether or not to append the data written.
1.72 + *
1.73 + * @param fileName String The system-dependent filename.
1.74 + * @param append boolean if <code>true</code>, then data will be written
1.75 + * to the end of the file rather than the beginning.
1.76 + * @throws IOException if the named file exists but is a directory rather
1.77 + * than a regular file, does not exist but cannot be
1.78 + * created, or cannot be opened for any other reason
1.79 + */
1.80 + public FileWriter(String fileName, boolean append) throws IOException {
1.81 + super(new FileOutputStream(fileName, append));
1.82 + }
1.83 +
1.84 + /**
1.85 + * Constructs a FileWriter object given a File object.
1.86 + *
1.87 + * @param file a File object to write to.
1.88 + * @throws IOException if the file exists but is a directory rather than
1.89 + * a regular file, does not exist but cannot be created,
1.90 + * or cannot be opened for any other reason
1.91 + */
1.92 + public FileWriter(File file) throws IOException {
1.93 + super(new FileOutputStream(file));
1.94 + }
1.95 +
1.96 + /**
1.97 + * Constructs a FileWriter object given a File object. If the second
1.98 + * argument is <code>true</code>, then bytes will be written to the end
1.99 + * of the file rather than the beginning.
1.100 + *
1.101 + * @param file a File object to write to
1.102 + * @param append if <code>true</code>, then bytes will be written
1.103 + * to the end of the file rather than the beginning
1.104 + * @throws IOException if the file exists but is a directory rather than
1.105 + * a regular file, does not exist but cannot be created,
1.106 + * or cannot be opened for any other reason
1.107 + * @since 1.4
1.108 + */
1.109 + public FileWriter(File file, boolean append) throws IOException {
1.110 + super(new FileOutputStream(file, append));
1.111 + }
1.112 +
1.113 + /**
1.114 + * Constructs a FileWriter object associated with a file descriptor.
1.115 + *
1.116 + * @param fd FileDescriptor object to write to.
1.117 + */
1.118 + public FileWriter(FileDescriptor fd) {
1.119 + super(new FileOutputStream(fd));
1.120 + }
1.121 +
1.122 +}