java.io
Class FileWriter

java.lang.Object sample code for java.lang.Object definition code for java.lang.Object 
  extended by java.io.Writer sample code for java.io.Writer definition code for java.io.Writer 
      extended by java.io.OutputStreamWriter sample code for java.io.OutputStreamWriter definition code for java.io.OutputStreamWriter 
          extended by java.io.FileWriter
All Implemented Interfaces:
Closeable sample code for java.io.Closeable definition code for java.io.Closeable , Flushable sample code for java.io.Flushable definition code for java.io.Flushable , Appendable sample code for java.lang.Appendable definition code for java.lang.Appendable

public class FileWriter
extends OutputStreamWriter sample code for java.io.OutputStreamWriter definition code for java.io.OutputStreamWriter

Convenience class for writing character files. The constructors of this class assume that the default character encoding and the default byte-buffer size are acceptable. To specify these values yourself, construct an OutputStreamWriter on a FileOutputStream.

Whether or not a file is available or may be created depends upon the underlying platform. Some platforms, in particular, allow a file to be opened for writing by only one FileWriter (or other file-writing object) at a time. In such situations the constructors in this class will fail if the file involved is already open.

FileWriter is meant for writing streams of characters. For writing streams of raw bytes, consider using a FileOutputStream.

Since:
JDK1.1
See Also:
OutputStreamWriter sample code for java.io.OutputStreamWriter definition code for java.io.OutputStreamWriter , FileOutputStream sample code for java.io.FileOutputStream definition code for java.io.FileOutputStream

Field Summary
 
Fields inherited from class java.io.Writer sample code for java.io.Writer definition code for java.io.Writer
lock sample code for java.io.Writer.lock definition code for java.io.Writer.lock
 
Constructor Summary
FileWriter sample code for java.io.FileWriter.FileWriter(java.io.File) definition code for java.io.FileWriter.FileWriter(java.io.File) (File sample code for java.io.File definition code for java.io.File  file)
          Constructs a FileWriter object given a File object.
FileWriter sample code for java.io.FileWriter.FileWriter(java.io.File, boolean) definition code for java.io.FileWriter.FileWriter(java.io.File, boolean) (File sample code for java.io.File definition code for java.io.File  file, boolean append)
          Constructs a FileWriter object given a File object.
FileWriter sample code for java.io.FileWriter.FileWriter(java.io.FileDescriptor) definition code for java.io.FileWriter.FileWriter(java.io.FileDescriptor) (FileDescriptor sample code for java.io.FileDescriptor definition code for java.io.FileDescriptor  fd)
          Constructs a FileWriter object associated with a file descriptor.
FileWriter sample code for java.io.FileWriter.FileWriter(java.lang.String) definition code for java.io.FileWriter.FileWriter(java.lang.String) (String sample code for java.lang.String definition code for java.lang.String  fileName)
          Constructs a FileWriter object given a file name.
FileWriter sample code for java.io.FileWriter.FileWriter(java.lang.String, boolean) definition code for java.io.FileWriter.FileWriter(java.lang.String, boolean) (String sample code for java.lang.String definition code for java.lang.String  fileName, boolean append)
          Constructs a FileWriter object given a file name with a boolean indicating whether or not to append the data written.
 
Method Summary
 
Methods inherited from class java.io.OutputStreamWriter sample code for java.io.OutputStreamWriter definition code for java.io.OutputStreamWriter
close sample code for java.io.OutputStreamWriter.close() definition code for java.io.OutputStreamWriter.close() , flush sample code for java.io.OutputStreamWriter.flush() definition code for java.io.OutputStreamWriter.flush() , getEncoding sample code for java.io.OutputStreamWriter.getEncoding() definition code for java.io.OutputStreamWriter.getEncoding() , write sample code for java.io.OutputStreamWriter.write(char[], int, int) definition code for java.io.OutputStreamWriter.write(char[], int, int) , write sample code for java.io.OutputStreamWriter.write(int) definition code for java.io.OutputStreamWriter.write(int) , write sample code for java.io.OutputStreamWriter.write(java.lang.String, int, int) definition code for java.io.OutputStreamWriter.write(java.lang.String, int, int)
 
Methods inherited from class java.io.Writer sample code for java.io.Writer definition code for java.io.Writer
append sample code for java.io.Writer.append(char) definition code for java.io.Writer.append(char) , append sample code for java.io.Writer.append(java.lang.CharSequence) definition code for java.io.Writer.append(java.lang.CharSequence) , append sample code for java.io.Writer.append(java.lang.CharSequence, int, int) definition code for java.io.Writer.append(java.lang.CharSequence, int, int) , write sample code for java.io.Writer.write(char[]) definition code for java.io.Writer.write(char[]) , write sample code for java.io.Writer.write(java.lang.String) definition code for java.io.Writer.write(java.lang.String)
 
Methods inherited from class java.lang.Object sample code for java.lang.Object definition code for java.lang.Object
clone sample code for java.lang.Object.clone() definition code for java.lang.Object.clone() , equals sample code for java.lang.Object.equals(java.lang.Object) definition code for java.lang.Object.equals(java.lang.Object) , finalize sample code for java.lang.Object.finalize() definition code for java.lang.Object.finalize() , getClass sample code for java.lang.Object.getClass() definition code for java.lang.Object.getClass() , hashCode sample code for java.lang.Object.hashCode() definition code for java.lang.Object.hashCode() , notify sample code for java.lang.Object.notify() definition code for java.lang.Object.notify() , notifyAll sample code for java.lang.Object.notifyAll() definition code for java.lang.Object.notifyAll() , toString sample code for java.lang.Object.toString() definition code for java.lang.Object.toString() , wait sample code for java.lang.Object.wait() definition code for java.lang.Object.wait() , wait sample code for java.lang.Object.wait(long) definition code for java.lang.Object.wait(long) , wait sample code for java.lang.Object.wait(long, int) definition code for java.lang.Object.wait(long, int)
 

Constructor Detail

FileWriter sample code for java.io.FileWriter(java.lang.String) definition code for java.io.FileWriter(java.lang.String)

public FileWriter(String sample code for java.lang.String definition code for java.lang.String  fileName)
           throws IOException sample code for java.io.IOException definition code for java.io.IOException 
Constructs a FileWriter object given a file name.

Parameters:
fileName - String The system-dependent filename.
Throws:
IOException sample code for java.io.IOException definition code for java.io.IOException - if the named file exists but is a directory rather than a regular file, does not exist but cannot be created, or cannot be opened for any other reason

FileWriter sample code for java.io.FileWriter(java.lang.String, boolean) definition code for java.io.FileWriter(java.lang.String, boolean)

public FileWriter(String sample code for java.lang.String definition code for java.lang.String  fileName,
                  boolean append)
           throws IOException sample code for java.io.IOException definition code for java.io.IOException 
Constructs a FileWriter object given a file name with a boolean indicating whether or not to append the data written.

Parameters:
fileName - String The system-dependent filename.
append - boolean if true, then data will be written to the end of the file rather than the beginning.
Throws:
IOException sample code for java.io.IOException definition code for java.io.IOException - if the named file exists but is a directory rather than a regular file, does not exist but cannot be created, or cannot be opened for any other reason

FileWriter sample code for java.io.FileWriter(java.io.File) definition code for java.io.FileWriter(java.io.File)

public FileWriter(File sample code for java.io.File definition code for java.io.File  file)
           throws IOException sample code for java.io.IOException definition code for java.io.IOException 
Constructs a FileWriter object given a File object.

Parameters:
file - a File object to write to.
Throws:
IOException sample code for java.io.IOException definition code for java.io.IOException - if the file exists but is a directory rather than a regular file, does not exist but cannot be created, or cannot be opened for any other reason

FileWriter sample code for java.io.FileWriter(java.io.File, boolean) definition code for java.io.FileWriter(java.io.File, boolean)

public FileWriter(File sample code for java.io.File definition code for java.io.File  file,
                  boolean append)
           throws IOException sample code for java.io.IOException definition code for java.io.IOException 
Constructs a FileWriter object given a File object. If the second argument is true, then bytes will be written to the end of the file rather than the beginning.

Parameters:
file - a File object to write to
append - if true, then bytes will be written to the end of the file rather than the beginning
Throws:
IOException sample code for java.io.IOException definition code for java.io.IOException - if the file exists but is a directory rather than a regular file, does not exist but cannot be created, or cannot be opened for any other reason
Since:
1.4

FileWriter sample code for java.io.FileWriter(java.io.FileDescriptor) definition code for java.io.FileWriter(java.io.FileDescriptor)

public FileWriter(FileDescriptor sample code for java.io.FileDescriptor definition code for java.io.FileDescriptor  fd)
Constructs a FileWriter object associated with a file descriptor.

Parameters:
fd - FileDescriptor object to write to.