public class FileUtil
extends java.lang.Object
FileUtil contains static methods for working with files.| Modifier and Type | Method | Description |
|---|---|---|
static java.io.PrintWriter |
bgzipPrintWriter(java.io.File file) |
Returns a buffered
java.io.PrintWriter that compresses
data using the BGZIP algorithm and writes the compressed data
to the specified file. |
static java.io.PrintWriter |
bgzipPrintWriter(java.io.File file,
boolean append) |
Returns a buffered
java.io.PrintWriter that compresses
data using the BGZIP algorithm and writes the compressed data to
the specified file. |
static java.io.InputStream |
bufferedInputStream(java.io.File file) |
Returns an buffered
java.io.InputStream with default buffer
size reading from the specified file. |
static java.io.OutputStream |
bufferedOutputStream(java.io.File file) |
Returns an buffered
java.io.OutputStream with default
buffer size writing to the specified file. |
static java.io.OutputStream |
bufferedOutputStream(java.io.File file,
boolean append) |
Returns an buffered
java.io.OutputStream with default
buffer size writing to the specified file. |
static java.io.PrintWriter |
gzipPrintWriter(java.io.File file) |
Returns a buffered
java.io.PrintWriter writing to
the specified file. |
static java.io.PrintWriter |
gzipPrintWriter(java.io.File file,
boolean append) |
Returns a buffered
java.io.PrintWriter writing to
the specified file. |
static java.io.PrintWriter |
nonBufferedPrintWriter(java.io.File file,
boolean append) |
Returns an unbuffered
java.io.PrintWriter writing to
the specified file. |
static java.io.PrintWriter |
printWriter(java.io.File file) |
Returns a buffered
java.io.PrintWriter writing to the
specified file. |
static java.io.PrintWriter |
printWriter(java.io.File file,
boolean append) |
Returns a buffered
java.io.PrintWriter writing to
the specified file. |
static java.io.RandomAccessFile |
randomAccessFile(java.io.File file,
java.lang.String mode) |
Returns a
java.io.RandomAccessFile to read from or optionally
to write to the specified file. |
static java.io.PrintWriter |
stdOutPrintWriter() |
Returns a
java.io.PrintWriter that writes
to standard out. |
static java.io.File |
tempFile(java.lang.String prefix) |
Returns a temporary
File that will be deleted when
the Java virtual machine exits. |
static java.io.File |
tempFile(java.lang.String prefix,
java.io.File directory) |
Creates and returns a new empty temporary file in the specified
directory.
|
public static java.io.File tempFile(java.lang.String prefix,
java.io.File directory)
prefix - a prefix of at least 3 characters for the temporary
filenamedirectory - the directory in which the temporary file is to
be created.java.lang.NullPointerException - if
prefix == null || directory == nullpublic static java.io.RandomAccessFile randomAccessFile(java.io.File file,
java.lang.String mode)
java.io.RandomAccessFile to read from or optionally
to write to the specified file. If the input stream cannot
be opened, an error message will be printed and the java interpreter
will exit.file - a filemode - the access mode as described in the documentation for the
java.io.RandomAccessFile constructorsjava.io.RandomAccessFilejava.lang.NullPointerException - if file == null || mode == nullpublic static java.io.InputStream bufferedInputStream(java.io.File file)
java.io.InputStream with default buffer
size reading from the specified file. If the input stream cannot
be opened, an error message will be printed and the java interpreter
will exit.file - a filejava.io.InputStreamjava.lang.NullPointerException - if file == nullpublic static java.io.OutputStream bufferedOutputStream(java.io.File file)
java.io.OutputStream with default
buffer size writing to the specified file. If the file cannot
be opened for writing, an error message will be printed and the
Java Virtual Machine will exit.file - a filejava.io.OutputStreamjava.lang.NullPointerException - if file == nullpublic static java.io.OutputStream bufferedOutputStream(java.io.File file,
boolean append)
java.io.OutputStream with default
buffer size writing to the specified file. If the file cannot
be opened for writing, an error message will be printed and the
Java Virtual Machine will exit. If the specified file exists and
append is false, bytes written by the returned
java.io.OutputStream will overwrite the previously existing file.file - a fileappend - true if bytes will be appended to the end of
the filejava.io.OutputStreamjava.lang.NullPointerException - if file == nullpublic static java.io.PrintWriter stdOutPrintWriter()
java.io.PrintWriter that writes
to standard out.java.io.PrintWriter that writes
to standard outpublic static java.io.PrintWriter gzipPrintWriter(java.io.File file)
java.io.PrintWriter writing to
the specified file. The resulting file will be compressed using
the GZIP compression algorithm. If the file cannot be opened, an
error message will be printed and the java interpreter will exit.
If the specified file exists, bytes written by the returned
PrintWriter will overwrite the previously existing file.file - a filejava.io.PrintWriter writing to the specified filejava.lang.NullPointerException - if file == nullpublic static java.io.PrintWriter gzipPrintWriter(java.io.File file,
boolean append)
java.io.PrintWriter writing to
the specified file. The resulting file will be compressed using
the GZIP compression algorithm. If the file cannot be opened, an
error message will be printed and the java interpreter will exit.
If the specified file exists and append is false, bytes
written by the returned PrintWriter will overwrite the
previously existing file.file - a fileappend - true if bytes will be appended to the end of
the filejava.io.PrintWriter writing to the specified filejava.lang.NullPointerException - if file == nullpublic static java.io.PrintWriter bgzipPrintWriter(java.io.File file)
java.io.PrintWriter that compresses
data using the BGZIP algorithm and writes the compressed data
to the specified file. The close() method of the returned
PrintWriter will write an empty BGZIP block to the end of the
output stream. If the file cannot be opened for writing, an error
message will be printed and the Java Virtual Machine will exit.
If the specified file exists, bytes written by the returned
PrintWriter will overwrite the previously existing file.file - a filejava.io.PrintWriterjava.lang.NullPointerException - if file == nullpublic static java.io.PrintWriter bgzipPrintWriter(java.io.File file,
boolean append)
java.io.PrintWriter that compresses
data using the BGZIP algorithm and writes the compressed data to
the specified file. The close() method of the returned
PrintWriter will write an empty BGZIP block to the end of the
output stream. If the file cannot be opened for writing, an error
message will be printed and the Java Virtual Machine will exit.
If the specified file exists and append is false, bytes
written by the returned PrintWriter will overwrite the
previously existing file.file - a fileappend - true if bytes will be appended to the end of
the filejava.io.PrintWriterjava.lang.NullPointerException - if file == nullpublic static java.io.PrintWriter printWriter(java.io.File file)
java.io.PrintWriter writing to the
specified file. If the file cannot be opened, an error message
will be printed and the Java Virtual Machine will exit. If the specified
file exists, bytes written by the returned PrintWriter will
overwrite the previously existing file.file - a filejava.io.PrintWriter writing to
the specified filejava.lang.NullPointerException - if file == nullpublic static java.io.PrintWriter printWriter(java.io.File file,
boolean append)
java.io.PrintWriter writing to
the specified file. If the file cannot be opened, an error message will
be printed and the Java Virtual Machine will exit. If the specified
file exists and append is false, bytes written by the
returned PrintWriter will overwrite the previously existing file.file - a fileappend - true if the data will be appended
to the end of any existing filejava.io.PrintWriter writing to
the specified filejava.lang.NullPointerException - if file == nullpublic static java.io.PrintWriter nonBufferedPrintWriter(java.io.File file,
boolean append)
java.io.PrintWriter writing to
the specified file. If the file cannot be opened, an error message will
be printed and the Java Virtual Machine will exit. If the specified
file exists and append is false, bytes written by the
returned PrintWriter will overwrite the previously existing file.file - a fileappend - true if the data will be appended
to the end of any existing filejava.io.PrintWriter writing to
the specified filejava.lang.NullPointerException - if file == nullpublic static java.io.File tempFile(java.lang.String prefix)
File that will be deleted when
the Java virtual machine exits.prefix - the filename prefix.File a new empty file.java.lang.IllegalArgumentException - if prefix contains fewer than
three characters