Contents | Prev | Next | Index

22.16 The Class java.io.FileOutputStream

A file output stream writes output bytes to a file in a file system. What files are available or may be created depends on the host environment.

public class FileOutputStream extends OutputStream {
	public FileOutputStream(String path)
		throws SecurityException, FileNotFoundException;
	public FileOutputStream(File file)
		throws SecurityException, FileNotFoundException;
	public FileOutputStream(FileDescriptor fdObj)
		throws SecurityException;
	public final FileDescriptor getFD() throws IOException;
	public void write(int b) throws IOException;
	public void write(byte[] b)
		throws IOException, NullPointerException;
	public void write(byte[] b, int off, int len)
		throws IOException, NullPointerException,
			IndexOutOfBoundsException;
	public void close() throws IOException;
	protected void finalize() throws IOException;
}

22.16.1 public FileOutputStream(String path)
throws SecurityException, FileNotFoundException

This constructor initializes a newly created FileOutputStream by opening a connection to an actual file, the file named by the path name path in the file system. A new FileDescriptor object is created to represent this file connection.

First, if there is a security manager, its checkWrite method (§20.17.21) is called with the path argument as its argument.

If the actual file cannot be opened, a FileNotFoundException is thrown.

22.16.2 public FileOutputStream(File file)
throws SecurityException, FileNotFoundException

This constructor initializes a newly created FileOutputStream by opening a connection to an actual file, the file named by file in the file system. A new FileDescriptor object is created to represent this file connection.

First, if there is a security manager, its checkWrite method (§20.17.21) is called with the path represented by the file argument as its argument.

If the actual file cannot be opened, a FileNotFoundException is thrown.

22.16.3 public FileOutputStream(FileDescriptor fdObj)
throws SecurityException

This constructor initializes a newly created FileOutputStream by using the file descriptor fdObj, which represents an existing connection to an actual file in the file system.

First, if there is a security manager, its checkWrite method (§20.17.20) is called with the file descriptor fdObj argument as its argument.

22.16.4 public final FileDescriptor getFD() throws IOException

This method returns the FileDescriptor object (§22.26) that represents the connection to the actual file in the file system being used by this FileOutputStream.

22.16.5 public void write(int b) throws IOException

The byte for this operation is written to the actual file to which this file output stream is connected.

Implements the write method of OutputStream (§22.15.1).

22.16.6 public void write(byte[] b)
throws IOException, NullPointerException

Bytes for this operation are written to the actual file to which this file output stream is connected.

Overrides the write method of OutputStream (§22.15.2).

22.16.7 public void write(byte[] b, int off, int len)
throws IOException, NullPointerException, IndexOutOfBoundsException

Bytes for this operation are written to the actual file to which this file output stream is connected.

Overrides the write method of OutputStream (§22.15.3).

22.16.8 public void close() throws IOException

This file output stream is closed and may no longer be used for writing bytes.

Overrides the close method of OutputStream (§22.15.5).

22.16.9 protected void finalize() throws IOException

A FileOutputStream uses finalization to clean up the connection to the actual file.


Contents | Prev | Next | Index

Java Language Specification (HTML generated by Suzette Pelouch on February 24, 1998)
Copyright © 1996 Sun Microsystems, Inc. All rights reserved
Please send any comments or corrections to [email protected]