|
Build 1.0_r1(from source) | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.io.OutputStream
java.io.FileOutputStream
public class FileOutputStream
FileOutputStream is a class whose underlying stream is represented by a file in the operating system. The bytes that are written to this stream are passed directly to the underlying operating system equivalent function. Since overhead may be high in writing to the OS, FileOutputStreams are usually wrapped with a BufferedOutputStream to reduce the number of times the OS is called.
BufferedOutputStream buf = new BufferedOutputStream(new FileOutputStream("aFile.txt"));
FileInputStream| Field Summary | |
|---|---|
(package private) FileDescriptor |
fd
The FileDescriptor representing this FileOutputStream. |
(package private) boolean |
innerFD
|
| Constructor Summary | |
|---|---|
FileOutputStream(File file)
Constructs a new FileOutputStream on the File file. |
|
FileOutputStream(File file,
boolean append)
Constructs a new FileOutputStream on the File file. |
|
FileOutputStream(FileDescriptor fd)
Constructs a new FileOutputStream on the FileDescriptor fd. |
|
FileOutputStream(String filename)
Constructs a new FileOutputStream on the file named fileName. |
|
FileOutputStream(String filename,
boolean append)
Constructs a new FileOutputStream on the file named filename. |
|
| Method Summary | |
|---|---|
void |
close()
Close the FileOutputStream. |
protected void |
finalize()
Frees any resources allocated to represent this FileOutputStream before it is garbage collected. |
FileChannel |
getChannel()
Returns the FileChannel equivalent to this output stream. |
FileDescriptor |
getFD()
Returns a FileDescriptor which represents the lowest level representation of a OS stream resource. |
void |
write(byte[] buffer)
Writes the entire contents of the byte array buffer to
this FileOutputStream. |
void |
write(byte[] buffer,
int offset,
int count)
Writes count bytes from the byte array
buffer starting at offset to this
FileOutputStream. |
void |
write(int oneByte)
Writes the specified byte oneByte to this
FileOutputStream. |
| Methods inherited from class java.io.OutputStream |
|---|
flush |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
FileDescriptor fd
boolean innerFD
| Constructor Detail |
|---|
public FileOutputStream(File file)
throws FileNotFoundException
file. If
the file exists, it is written over. See the constructor which can append
to the file if so desired.
file - the File on which to stream reads.
FileNotFoundException - If the file cannot be opened for writing.SecurityManager.checkWrite(FileDescriptor)
public FileOutputStream(File file,
boolean append)
throws FileNotFoundException
file. If
the file exists, it is written over. The parameter append
determines whether or not the file is opened and appended to or just
opened empty.
file - the File on which to stream reads.append - a boolean indicating whether or not to append to an existing
file.
FileNotFoundException - If the file cannot be opened for writing.SecurityManager.checkWrite(FileDescriptor),
SecurityManager.checkWrite(String)public FileOutputStream(FileDescriptor fd)
fd.
The file must already be open, therefore no FileIOException
will be thrown.
fd - the FileDescriptor on which to stream writes.SecurityManager.checkWrite(FileDescriptor)
public FileOutputStream(String filename)
throws FileNotFoundException
fileName.
If the file exists, it is written over. See the constructor which can
append to the file if so desired. The fileName may be
absolute or relative to the System property "user.dir".
filename - the file on which to stream writes.
FileNotFoundException - If the filename cannot be opened for writing.
public FileOutputStream(String filename,
boolean append)
throws FileNotFoundException
filename.
If the file exists, it is written over. The parameter append
determines whether or not the file is opened and appended to or just
opened empty. The filename may be absolute or relative to
the System property "user.dir".
filename - the file on which to stream writes.append - a boolean indicating whether or not to append to an existing
file.
FileNotFoundException - If the filename cannot be opened for writing.| Method Detail |
|---|
public void close()
throws IOException
close in interface Closeableclose in class OutputStreamIOException - If an error occurs attempting to close this FileOutputStream.
protected void finalize()
throws IOException
finalize in class ObjectIOException - If an error occurs attempting to finalize this
FileOutputStream.public FileChannel getChannel()
The file channel is write-only and has an initial position within the file that is the same as the current position of this FileOutputStream within the file. All changes made to the underlying file descriptor state via the channel are visible by the output stream and vice versa.
public final FileDescriptor getFD()
throws IOException
IOException - If the Stream is already closed and there is no
FileDescriptor.
public void write(byte[] buffer)
throws IOException
buffer to
this FileOutputStream.
write in class OutputStreambuffer - the buffer to be written
IOException - If an error occurs attempting to write to this
FileOutputStream.
public void write(byte[] buffer,
int offset,
int count)
throws IOException
count bytes from the byte array
buffer starting at offset to this
FileOutputStream.
write in class OutputStreambuffer - the buffer to be writtenoffset - offset in buffer to get bytescount - number of bytes in buffer to write
IOException - If an error occurs attempting to write to this
FileOutputStream.
IndexOutOfBoundsException - If offset or count are outside of bounds.
NullPointerException - If buffer is null.
public void write(int oneByte)
throws IOException
oneByte to this
FileOutputStream. Only the low order byte of oneByte is
written.
write in class OutputStreamoneByte - the byte to be written
IOException - If an error occurs attempting to write to this
FileOutputStream.
|
Build 1.0_r1(from source) | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||