Index (Frames) | Index (No Frames) | Package | Package Tree | Tree
java.io

Class FileOutputStream

java.lang.Object
|
+--java.io.OutputStream
   |
   +--java.io.FileOutputStream


public class FileOutputStream

extends OutputStream

This classes allows a stream of data to be written to a disk file or any open FileDescriptor.

Author:

Constructor Summary

FileOutputStream(java.lang.String name)

This method initializes a FileOutputStream object to write to the named file.
FileOutputStream(java.io.File file)

This method initializes a FileOutputStream object to write to the specified File object.
FileOutputStream(java.lang.String name, boolean append)

This method initializes a FileOutputStream object to write to the named file.
FileOutputStream(java.io.FileDescriptor fd)

This method initializes a FileOutputStream object to write to the file represented by the specified FileDescriptor object.

Method Summary

synchronized voidclose()

This method closes the underlying file.
voidfinalize()

This method closes the stream when this object is being garbage collected.
java.nio.channels.FileChannelgetChannel()

java.io.FileDescriptorgetFD()

This method returns a FileDescriptor object representing the file that is currently being written to
synchronized voidwrite(int b)

This method writes a single byte of data to the file.
synchronized voidwrite(byte[] buf)

This method writes all the bytes in the specified array to the file.
synchronized voidwrite(byte[] buf, int offset, int len)

This method writes len bytes from the byte array buf to the file starting at index offset.

Constructor Details

FileOutputStream

public FileOutputStream(java.io.File file)

This method initializes a FileOutputStream object to write to the specified File object. The file is created if it does not exist, and the bytes written are written starting at the beginning of the file.

Before opening a file, a security check is performed by calling the checkWrite method of the SecurityManager (if one exists) with the name of the file to be opened. An exception is thrown if writing is not allowed.

Parameters:

Throws:


FileOutputStream

public FileOutputStream(java.io.FileDescriptor fd)

This method initializes a FileOutputStream object to write to the file represented by the specified FileDescriptor object. This method does not create any underlying disk file or reposition the file pointer of the given descriptor. It assumes that this descriptor is ready for writing as is.

Before opening a file, a security check is performed by calling the checkWrite method of the SecurityManager (if one exists) with the specified FileDescriptor as an argument. An exception is thrown if writing is not allowed.

Parameters:

Throws:


FileOutputStream

public FileOutputStream(java.lang.String name)

This method initializes a FileOutputStream object to write to the named file. The file is created if it does not exist, and the bytes written are written starting at the beginning of the file.

Before opening a file, a security check is performed by calling the checkWrite method of the SecurityManager (if one exists) with the name of the file to be opened. An exception is thrown if writing is not allowed.

Parameters:

Throws:


FileOutputStream

public FileOutputStream(java.lang.String name, boolean append)

This method initializes a FileOutputStream object to write to the named file. The file is created if it does not exist, and the bytes written are written starting at the beginning of the file if the append argument is false or at the end of the file if the append argument is true.

Before opening a file, a security check is performed by calling the checkWrite method of the SecurityManager (if one exists) with the name of the file to be opened. An exception is thrown if writing is not allowed.

Parameters:

Throws:


Method Details

close

public synchronized void close()

This method closes the underlying file. Any further attempts to write to this stream will likely generate an exception since the file is closed.

Throws:


finalize

protected void finalize()

This method closes the stream when this object is being garbage collected.

Throws:


getChannel

public FileChannel getChannel()


getFD

public final FileDescriptor getFD()

This method returns a FileDescriptor object representing the file that is currently being written to

Returns:

Throws:


write

public synchronized void write(byte[] buf)

This method writes all the bytes in the specified array to the file.

Parameters:

Throws:


write

public synchronized void write(byte[] buf, int offset, int len)

This method writes len bytes from the byte array buf to the file starting at index offset.

Parameters:

Throws:


write

public synchronized void write(int b)

This method writes a single byte of data to the file.

Parameters:

Throws: