Java.io.FileWriter Class


Advertisements


Introduction

The Java.io.FileWriter class is a convenience class for writing character files.Following are the important points about FileWriter:

  • The constructors of this class assume that the default character encoding and the default byte-buffer size are acceptable.

  • FileWriter is meant for writing streams of characters. For writing streams of raw bytes, use FileOutputStream.

Class declaration

Following is the declaration for Java.io.FileWriter class:

public class FileWriter
   extends OutputStreamReader

Field

Following are the fields for Java.io.FileWriter class:

  • protected Object lock -- This is the object used to synchronize operations on this stream.

Class constructors

S.N. Constructor & Description
1

FileWriter(File file)

This constructs a FileWriter object given a File object.

2

FileWriter(File file, boolean append)

This constructs a FileWriter object given a File object.

3

FileWriter(FileDescriptor fd)

This constructs a FileWriter object associated with a file descriptor.

4

FileWriter(String fileName)

This constructs a FileWriter object given a file name.

5

FileWriter(String fileName, boolean append)

This constructs a FileWriter object given a file name with a boolean indicating whether or not to append the data written.

Class Methods

This class inherits methods from the following classes:

  • Java.io.OutputStreamWriter
  • java.uti.Writer
  • Java.io.Object


Advertisements