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 classFileOutputStream
extends OutputStream { publicFileOutputStream
(String path) throws SecurityException, FileNotFoundException; publicFileOutputStream
(File file) throws SecurityException, FileNotFoundException; publicFileOutputStream
(FileDescriptor fdObj) throws SecurityException; public voidwrite
(int b) throws IOException; public voidwrite
(byte[] b) throws IOException, NullPointerException; public voidwrite
(byte[] b, int off, int len) throws IOException, NullPointerException, IndexOutOfBoundsException; public voidclose
() throws IOException; public final FileDescriptorgetFD
() throws IOException; protected voidfinalize
() 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.