@Immutable public final class TFileOutputStream extends net.java.truecommons.io.DecoratingOutputStream
FileOutputStream
for writing plain old
files or entries in an archive file.
Mind that applications cannot write archive files directly - just their
entries!
To prevent exceptions to be thrown subsequently, applications should always close their streams using the following idiom:
TFileOutputStream out = new TFileOutputStream(file);
try {
// Do I/O here...
} finally {
out.close(); // ALWAYS close the stream!
}
Note that the DecoratingOutputStream.close()
method may throw an IOException
, too.
Applications need to deal with this appropriately, for example by enclosing
the entire block with another try-catch
-block:
try {
TFileOutputStream out = new TFileOutputStream(file);
try {
// Do I/O here...
} finally {
out.close(); // ALWAYS close the stream!
}
} catch (IOException ex) {
ex.printStackTrace();
}
Applications cannot write to an entry in an archive file if an implicit
unmount is required but cannot get performed
because another TFileInputStream
or TFileOutputStream
object
hasn't been closed or garbage collected yet.
A FileNotFoundException
is thrown by the constructors of this class
in this case.
If you would like to use this class in order to cp files,
please consider using one of the
cp methods of the class TFile
instead.
These methods provide ease of use, enhanced features, superior performance
and require less space in the temp file folder.
TFile.cat(InputStream, OutputStream)
,
TConfig.setLenient(boolean)
,
TFileInputStream
Constructor and Description |
---|
TFileOutputStream(File file)
Constructs a new output stream for writing plain old files or entries
in an archive file.
|
TFileOutputStream(File file,
net.java.truecommons.shed.BitField<FsAccessOption> options)
Constructs a new output stream for writing plain old files or entries
in an archive file.
|
TFileOutputStream(File file,
boolean append)
Constructs a new output stream for writing plain old files or entries
in an archive file.
|
TFileOutputStream(File file,
FsAccessOption... options)
Constructs a new output stream for writing plain old files or entries
in an archive file.
|
TFileOutputStream(String path)
Constructs a new output stream for writing plain old files or entries
in an archive file.
|
TFileOutputStream(String path,
boolean append)
Constructs a new output stream for writing plain old files or entries
in an archive file.
|
TFileOutputStream(String path,
FsAccessOption... options)
Constructs a new output stream for writing plain old files or entries
in an archive file.
|
@CreatesObligation public TFileOutputStream(File file) throws IOException
file
- the file or archive entry.IOException
- on any I/O error.@CreatesObligation public TFileOutputStream(File file, net.java.truecommons.shed.BitField<FsAccessOption> options) throws IOException
file
- the file or archive entry.options
- additional options for accessing the file or archive
entry.IOException
- on any I/O error.@CreatesObligation public TFileOutputStream(File file, boolean append) throws IOException
file
- the file or archive entry.append
- if the data shall get appended to the file or archive
entry rather than replacing it.IOException
- on any I/O error.@CreatesObligation public TFileOutputStream(File file, FsAccessOption... options) throws IOException
file
- the file or archive entry.options
- additional options for accessing the file or archive
entry.IOException
- on any I/O error.@CreatesObligation public TFileOutputStream(String path) throws IOException
path
- the path of the file or archive entry.IOException
- on any I/O error.@CreatesObligation public TFileOutputStream(String path, boolean append) throws IOException
path
- the path of the file or archive entry.append
- if the data shall get appended to the file or archive
entry rather than replacing it.IOException
- on any I/O error.@CreatesObligation public TFileOutputStream(String path, FsAccessOption... options) throws IOException
path
- the path of the file or archive entry.options
- additional options for accessing the file or archive
entry.IOException
- on any I/O error.Copyright © 2005–2018 Schlichtherle IT Services. All rights reserved.