public class IOUtils
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static void |
closeQuietly(java.io.Closeable closeable)
Closes a closeable resource, catching its
IOException . |
static java.lang.String |
getFileContents(java.io.File file)
Reads the contents of a text file.
|
static java.lang.String |
getFileContents(java.io.File file,
java.lang.String charset)
Reads the contents of a text file.
|
static java.lang.String |
getFileExtension(java.io.File file)
Gets the extension off a file's name.
|
static byte[] |
toByteArray(java.io.InputStream in)
Reads all the bytes from an input stream.
|
static byte[] |
toByteArray(java.io.InputStream in,
boolean close)
Reads all the bytes from an input stream.
|
static java.lang.String |
toString(java.io.Reader reader)
Reads the contents of a
Reader into a String. |
static java.io.Reader |
utf8Reader(java.io.File file)
Creates a reader whose character encoding is set to "UTF-8".
|
static java.io.Reader |
utf8Reader(java.io.InputStream in)
Creates a reader whose character encoding is set to "UTF-8".
|
static java.io.Writer |
utf8Writer(java.io.File file)
Creates a writer whose character encoding is set to "UTF-8".
|
static java.io.Writer |
utf8Writer(java.io.File file,
boolean append)
Creates a writer whose character encoding is set to "UTF-8".
|
static java.io.Writer |
utf8Writer(java.io.OutputStream out)
Creates a writer whose character encoding is set to "UTF-8".
|
public static java.lang.String getFileExtension(java.io.File file)
file
- the filepublic static byte[] toByteArray(java.io.InputStream in) throws java.io.IOException
in
- the input streamjava.io.IOException
- if there's a problem reading from the input streampublic static byte[] toByteArray(java.io.InputStream in, boolean close) throws java.io.IOException
in
- the input streamclose
- true to close the input stream when done, false not tojava.io.IOException
- if there's a problem reading from the input streampublic static java.lang.String toString(java.io.Reader reader) throws java.io.IOException
Reader
into a String.reader
- the readerjava.io.IOException
- if there was a problem reading from the readerpublic static java.lang.String getFileContents(java.io.File file) throws java.io.IOException
file
- the file to readjava.io.IOException
- if there's a problem reading the filepublic static java.lang.String getFileContents(java.io.File file, java.lang.String charset) throws java.io.IOException
file
- the file to readcharset
- the character encoding of the filejava.io.IOException
- if there's a problem reading the filepublic static void closeQuietly(java.io.Closeable closeable)
IOException
.closeable
- the resource to close (can be null)public static java.io.Writer utf8Writer(java.io.OutputStream out)
out
- the output stream to write topublic static java.io.Writer utf8Writer(java.io.File file) throws java.io.FileNotFoundException
file
- the file to write tojava.io.FileNotFoundException
- if the file cannot be written topublic static java.io.Writer utf8Writer(java.io.File file, boolean append) throws java.io.FileNotFoundException
file
- the file to write toappend
- true to append to the end of the file, false to overwrite
itjava.io.FileNotFoundException
- if the file cannot be written topublic static java.io.Reader utf8Reader(java.io.InputStream in)
in
- the input stream to read frompublic static java.io.Reader utf8Reader(java.io.File file) throws java.io.FileNotFoundException
file
- the file to read fromjava.io.FileNotFoundException
- if the file can't be readThis software is published under the BSD license. Copyright © 2003-${build.year}, CRIXP AG, Switzerland, All rights reserved. Use is subject to license terms.