public class IOUtils extends Object
Modifier and Type | Method and Description |
---|---|
static void |
closeQuietly(Closeable closeable)
Closes a closeable resource, catching its
IOException . |
static String |
getFileContents(File file)
Reads the contents of a text file.
|
static String |
getFileContents(File file,
String charset)
Reads the contents of a text file.
|
static String |
getFileExtension(File file)
Gets the extension off a file's name.
|
static byte[] |
toByteArray(InputStream in)
Reads all the bytes from an input stream.
|
static byte[] |
toByteArray(InputStream in,
boolean close)
Reads all the bytes from an input stream.
|
static String |
toString(Reader reader)
Reads the contents of a
Reader into a String. |
static Reader |
utf8Reader(File file)
Creates a reader whose character encoding is set to "UTF-8".
|
static Reader |
utf8Reader(InputStream in)
Creates a reader whose character encoding is set to "UTF-8".
|
static Writer |
utf8Writer(File file)
Creates a writer whose character encoding is set to "UTF-8".
|
static Writer |
utf8Writer(File file,
boolean append)
Creates a writer whose character encoding is set to "UTF-8".
|
static Writer |
utf8Writer(OutputStream out)
Creates a writer whose character encoding is set to "UTF-8".
|
public static String getFileExtension(File file)
file
- the filepublic static byte[] toByteArray(InputStream in) throws IOException
in
- the input streamIOException
- if there's a problem reading from the input streampublic static byte[] toByteArray(InputStream in, boolean close) throws IOException
in
- the input streamclose
- true to close the input stream when done, false not toIOException
- if there's a problem reading from the input streampublic static String toString(Reader reader) throws IOException
Reader
into a String.reader
- the readerIOException
- if there was a problem reading from the readerpublic static String getFileContents(File file) throws IOException
file
- the file to readIOException
- if there's a problem reading the filepublic static String getFileContents(File file, String charset) throws IOException
file
- the file to readcharset
- the character encoding of the fileIOException
- if there's a problem reading the filepublic static void closeQuietly(Closeable closeable)
IOException
.closeable
- the resource to close (can be null)public static Writer utf8Writer(OutputStream out)
out
- the output stream to write topublic static Writer utf8Writer(File file) throws FileNotFoundException
file
- the file to write toFileNotFoundException
- if the file cannot be written topublic static Writer utf8Writer(File file, boolean append) throws FileNotFoundException
file
- the file to write toappend
- true to append to the end of the file, false to overwrite
itFileNotFoundException
- if the file cannot be written topublic static Reader utf8Reader(InputStream in)
in
- the input stream to read frompublic static Reader utf8Reader(File file) throws FileNotFoundException
file
- the file to read fromFileNotFoundException
- 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.