public class FileOutput extends Object implements AutoCloseable
Modifier and Type | Field and Description |
---|---|
private BufferedOutputStream |
buffer |
private static String |
DEFAULT_ENCODING |
private String |
fileEncoding |
Constructor and Description |
---|
FileOutput()
Create a null file output object similar to writing to /dev/null.
|
FileOutput(String dataFileName)
Create a file with the given name.
|
FileOutput(String dataFileName,
boolean addVersion)
Create a file with the given name.
|
FileOutput(String dataFileName,
boolean addVersion,
boolean append)
Create a file with the given name.
|
FileOutput(String dataFileName,
boolean addVersion,
boolean append,
String encoding)
Create a file with the given name.
|
Modifier and Type | Method and Description |
---|---|
void |
close() |
void |
flush()
Flushes the file stream.
|
static void |
saveToFile(String dataFileName,
String data,
boolean addVersion)
Save data in the form of a string to a named file.
|
static void |
saveToFile(String dataFileName,
String format,
boolean addVersion,
Object... args)
Save data in the form of a string to a named file.
|
void |
write(String str)
Write the string to the file stream.
|
String |
write(String format,
Object... args)
Writes a formatted string to the file stream.
|
private BufferedOutputStream buffer
private String fileEncoding
private static final String DEFAULT_ENCODING
public FileOutput()
public FileOutput(String dataFileName)
dataFileName
- the name of the file.public FileOutput(String dataFileName, boolean addVersion)
dataFileName
- the name of the file.addVersion
- boolean that determines whether or not the project version number should be applied to the
start of the file.public FileOutput(String dataFileName, boolean addVersion, boolean append)
dataFileName
- the name of the file.addVersion
- boolean that determines whether or not the project version number should be applied to the
start of the file.append
- if true
, then bytes will be written to the end of the file.public FileOutput(String dataFileName, boolean addVersion, boolean append, String encoding)
dataFileName
- the name of the file.addVersion
- boolean that determines whether or not the project version number should be applied to the
start of the file.append
- if true
, then bytes will be written to the end of the file.encoding
- the character encoding used in the file.public final void write(String str)
str
- the string to write to the stream.public final String write(String format, Object... args)
format
- A format string as described in Format string syntaxargs
- Arguments referenced by the format specifiers in the format string. If there are more arguments
than format specifiers, the extra arguments are ignored. The maximum number of arguments is limited
by the maximum dimension of a Java array as defined by the Java Virtual Machine Specificationpublic final void close()
close
in interface AutoCloseable
public final void flush()
public static void saveToFile(String dataFileName, String data, boolean addVersion)
dataFileName
- the name of the file in which the data is to be saved.data
- the data to be saved.addVersion
- add the project version number to the start of the file.public static void saveToFile(String dataFileName, String format, boolean addVersion, Object... args)
dataFileName
- the name of the file in which the data is to be saved.format
- A format string as described in Format string syntaxaddVersion
- add the project version number to the start of the file.args
- Arguments referenced by the format specifiers in the format string. If there are more
arguments than format specifiers, the extra arguments are ignored. The maximum number of
arguments is limited by the maximum dimension of a Java array as defined by the Java Virtual Machine SpecificationCopyright © 2015 University of Glasgow. All rights reserved.