| Constructor: |
public FileOutputStream(File file) throws FileNotFoundException {
this(file, false);
}
Constructs a new FileOutputStream on the File {@code file}. If the file
exists, it is overwritten. Parameters:
file -
the file to which this stream writes.
Throws:
FileNotFoundException -
if {@code file} cannot be opened for writing.
SecurityException -
if a {@code SecurityManager} is installed and it denies the
write request.
Also see:
- java.lang.SecurityManager#checkWrite(FileDescriptor)
|
public FileOutputStream(FileDescriptor fd) {
super();
if (fd == null) {
throw new NullPointerException(Messages.getString("luni.B6")); //$NON-NLS-1$
}
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkWrite(fd);
}
this.fd = fd;
innerFD = false;
channel = FileChannelFactory.getFileChannel(this, fd.descriptor,
IFileSystem.O_WRONLY);
}
Constructs a new FileOutputStream on the FileDescriptor {@code fd}. The
file must already be open, therefore no {@code FileNotFoundException}
will be thrown. Parameters:
fd -
the FileDescriptor to which this stream writes.
Throws:
NullPointerException -
if {@code fd} is {@code null}.
SecurityException -
if a {@code SecurityManager} is installed and it denies the
write request.
Also see:
- java.lang.SecurityManager#checkWrite(FileDescriptor)
|
public FileOutputStream(String filename) throws FileNotFoundException {
this(filename, false);
}
Constructs a new FileOutputStream on the file named {@code filename}. If
the file exists, it is overwritten. The {@code filename} may be absolute
or relative to the system property {@code "user.dir"}. Parameters:
filename -
the name of the file to which this stream writes.
Throws:
FileNotFoundException -
if the file cannot be opened for writing.
SecurityException -
if a {@code SecurityManager} is installed and it denies the
write request.
|
public FileOutputStream(File file,
boolean append) throws FileNotFoundException {
super();
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkWrite(file.getPath());
}
fd = new FileDescriptor();
fd.descriptor = fileSystem.open(file.properPath(true),
append ? IFileSystem.O_APPEND : IFileSystem.O_WRONLY);
innerFD = true;
channel = FileChannelFactory.getFileChannel(this, fd.descriptor,
append ? IFileSystem.O_APPEND : IFileSystem.O_WRONLY);
}
Constructs a new FileOutputStream on the File {@code file}. The
parameter {@code append} determines whether or not the file is opened and
appended to or just opened and overwritten. Parameters:
file -
the file to which this stream writes.
append -
indicates whether or not to append to an existing file.
Throws:
FileNotFoundException -
if the {@code file} cannot be opened for writing.
SecurityException -
if a {@code SecurityManager} is installed and it denies the
write request.
Also see:
- java.lang.SecurityManager#checkWrite(FileDescriptor)
- java.lang.SecurityManager#checkWrite(String)
|
public FileOutputStream(String filename,
boolean append) throws FileNotFoundException {
this(new File(filename), append);
}
Constructs a new FileOutputStream on the file named {@code filename}.
The parameter {@code append} determines whether or not the file is opened
and appended to or just opened and overwritten. The {@code filename} may
be absolute or relative to the system property {@code "user.dir"}. Parameters:
filename -
the name of the file to which this stream writes.
append -
indicates whether or not to append to an existing file.
Throws:
FileNotFoundException -
if the file cannot be opened for writing.
SecurityException -
if a {@code SecurityManager} is installed and it denies the
write request.
|
| Method from java.io.FileOutputStream Detail: |
public void close() throws IOException {
if (fd == null) {
// if fd is null, then the underlying file is not opened, so nothing
// to close
return;
}
if (channel != null) {
synchronized (channel) {
if (channel.isOpen() && fd.descriptor >= 0) {
channel.close();
}
}
}
synchronized (this) {
if (fd.descriptor >= 0 && innerFD) {
fileSystem.close(fd.descriptor);
fd.descriptor = -1;
}
}
}
Closes this stream. This implementation closes the underlying operating
system resources allocated to represent this stream. |
protected void finalize() throws IOException {
close();
}
Frees any resources allocated for this stream before it is garbage
collected. This method is called from the Java Virtual Machine. |
public FileChannel getChannel() {
return channel;
}
Returns the FileChannel equivalent to this output stream.
The file channel is write-only and has an initial position within the
file that is the same as the current position of this stream 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 {
return fd;
}
Returns a FileDescriptor which represents the lowest level representation
of an operating system stream resource. |
public void write(byte[] buffer) throws IOException {
write(buffer, 0, buffer.length);
}
Writes the entire contents of the byte array {@code buffer} to this
stream. |
public void write(int oneByte) throws IOException {
openCheck();
byte[] byteArray = new byte[1];
byteArray[0] = (byte) oneByte;
fileSystem.write(fd.descriptor, byteArray, 0, 1);
}
Writes the specified byte {@code oneByte} to this stream. Only the low
order byte of the integer {@code oneByte} is written. |
public void write(byte[] buffer,
int offset,
int count) throws IOException {
if (buffer == null) {
throw new NullPointerException();
}
if (count < 0 || offset < 0 || offset > buffer.length
|| count > buffer.length - offset) {
throw new IndexOutOfBoundsException();
}
if (count == 0) {
return;
}
openCheck();
fileSystem.write(fd.descriptor, buffer, offset, count);
}
Writes {@code count} bytes from the byte array {@code buffer} starting at
{@code offset} to this stream. |