KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > io > FileWriter


1 /*
2  * @(#)FileWriter.java 1.18 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package java.io;
9
10
11 /**
12  * Convenience class for writing character files. The constructors of this
13  * class assume that the default character encoding and the default byte-buffer
14  * size are acceptable. To specify these values yourself, construct an
15  * OutputStreamWriter on a FileOutputStream.
16  *
17  * <p>Whether or not a file is available or may be created depends upon the
18  * underlying platform. Some platforms, in particular, allow a file to be
19  * opened for writing by only one <tt>FileWriter</tt> (or other file-writing
20  * object) at a time. In such situations the constructors in this class
21  * will fail if the file involved is already open.
22  *
23  * <p><code>FileWriter</code> is meant for writing streams of characters.
24  * For writing streams of raw bytes, consider using a
25  * <code>FileOutputStream</code>.
26  *
27  * @see OutputStreamWriter
28  * @see FileOutputStream
29  *
30  * @version 1.18, 03/12/19
31  * @author Mark Reinhold
32  * @since JDK1.1
33  */

34
35 public class FileWriter extends OutputStreamWriter JavaDoc {
36
37     /**
38      * Constructs a FileWriter object given a file name.
39      *
40      * @param fileName String The system-dependent filename.
41      * @throws IOException if the named file exists but is a directory rather
42      * than a regular file, does not exist but cannot be
43      * created, or cannot be opened for any other reason
44      */

45     public FileWriter(String JavaDoc fileName) throws IOException JavaDoc {
46     super(new FileOutputStream JavaDoc(fileName));
47     }
48
49     /**
50      * Constructs a FileWriter object given a file name with a boolean
51      * indicating whether or not to append the data written.
52      *
53      * @param fileName String The system-dependent filename.
54      * @param append boolean if <code>true</code>, then data will be written
55      * to the end of the file rather than the beginning.
56      * @throws IOException if the named file exists but is a directory rather
57      * than a regular file, does not exist but cannot be
58      * created, or cannot be opened for any other reason
59      */

60     public FileWriter(String JavaDoc fileName, boolean append) throws IOException JavaDoc {
61     super(new FileOutputStream JavaDoc(fileName, append));
62     }
63
64     /**
65      * Constructs a FileWriter object given a File object.
66      *
67      * @param file a File object to write to.
68      * @throws IOException if the file exists but is a directory rather than
69      * a regular file, does not exist but cannot be created,
70      * or cannot be opened for any other reason
71      */

72     public FileWriter(File JavaDoc file) throws IOException JavaDoc {
73     super(new FileOutputStream JavaDoc(file));
74     }
75
76     /**
77      * Constructs a FileWriter object given a File object. If the second
78      * argument is <code>true</code>, then bytes will be written to the end
79      * of the file rather than the beginning.
80      *
81      * @param file a File object to write to
82      * @param append if <code>true</code>, then bytes will be written
83      * to the end of the file rather than the beginning
84      * @throws IOException if the file exists but is a directory rather than
85      * a regular file, does not exist but cannot be created,
86      * or cannot be opened for any other reason
87      * @since 1.4
88      */

89     public FileWriter(File JavaDoc file, boolean append) throws IOException JavaDoc {
90         super(new FileOutputStream JavaDoc(file, append));
91     }
92
93     /**
94      * Constructs a FileWriter object associated with a file descriptor.
95      *
96      * @param fd FileDescriptor object to write to.
97      */

98     public FileWriter(FileDescriptor JavaDoc fd) {
99     super(new FileOutputStream JavaDoc(fd));
100     }
101
102 }
103
Popular Tags