public abstract class IOUtils extends Object
commons-io框架提供的方法。| 构造器和说明 |
|---|
IOUtils() |
| 限定符和类型 | 方法和说明 |
|---|---|
static void |
closeQuietly(Closeable closeable)
关闭
Closeable,该方法等效于Closeable.close()
该方法主要用于finally块中,并且忽略所有的异常
Example code:
Closeable closeable = null;
try {
closeable = new FileReader("foo.txt");
// process closeable
closeable.close();
} catch (Exception e) {
// error handling
} finally {
IOUtils.closeQuietly(closeable);
}
|
static int |
copy(InputStream in,
OutputStream out)
流的拷贝,超大流(超过2GB)拷贝返回的结果为-1。
|
static boolean |
copy(InputStream in,
Writer writer)
将输入流的字节数组转换为
Writer字符内容,使用系统默认编码。 |
static boolean |
copy(InputStream in,
Writer writer,
Charset encoding)
将输入流的字节数组转换为
Writer字符内容,使用系统默认编码。 |
static boolean |
copy(InputStream in,
Writer writer,
String encoding)
将输入流的字节数组转换为
Writer字符内容,使用系统默认编码。 |
static boolean |
copy(Reader reader,
OutputStream out)
将字符输入流转为字节输出流,使用平台默认编码
|
static boolean |
copy(Reader reader,
OutputStream out,
Charset encoding)
将字符输入流转为字节输出流,使用指定编码
|
static boolean |
copy(Reader reader,
OutputStream out,
String encoding)
将字符输入流转为字节输出流,使用指定编码
|
static int |
copy(Reader reader,
Writer writer)
将字符输入流转换为字符输出流,如果字符输入流的大小超过2GB,则返回-1
|
static long |
copyLarge(InputStream in,
OutputStream out)
流的拷贝,如果拷贝流失败则返回-1.
|
static long |
copyLarge(InputStream in,
OutputStream out,
byte[] buffer)
流的拷贝,如果拷贝流失败则返回-1.
|
static long |
copyLarge(Reader reader,
Writer writer)
字符流的拷贝,支持大字符流(超过2GB)拷贝
|
static long |
copyLarge(Reader reader,
Writer writer,
char[] buffer)
字符流的拷贝,支持大字符流(超过2GB)拷贝
|
static String |
md5Hex(InputStream in)
流的md5,结果由16进制字符串返回
|
static List<String> |
readLines(InputStream in)
从输入流中读取,采用平台默认编码
|
static List<String> |
readLines(InputStream in,
Charset charset)
从输入流中读取
|
static List<String> |
readLines(Reader reader)
从流中读取内容
|
static String |
sha1Hex(FileInputStream in)
流的SHA-1,结果由16进制字符串返回
|
static byte[] |
toByteArray(InputStream in)
将输入流转为字节数组
|
static byte[] |
toByteArray(InputStream in,
int size)
从输入流中读取指定长度的字节数组
|
static byte[] |
toByteArray(Reader reader)
将
Reader的内容转为字节数组,否转换异常则返回null |
static byte[] |
toByteArray(Reader reader,
Charset encoding)
将
Reader的内容转为字节数组,否转换异常则返回null |
static byte[] |
toByteArray(Reader reader,
String encoding)
将
Reader的内容转为字节数组,否转换异常则返回null |
static String |
toString(InputStream in) |
static String |
toString(InputStream in,
Charset encoding) |
static String |
toString(InputStream in,
String encoding) |
static String |
toString(Reader reader) |
public static void closeQuietly(Closeable closeable)
Closeable,该方法等效于Closeable.close()
该方法主要用于finally块中,并且忽略所有的异常
Example code:
Closeable closeable = null;
try {
closeable = new FileReader("foo.txt");
// process closeable
closeable.close();
} catch (Exception e) {
// error handling
} finally {
IOUtils.closeQuietly(closeable);
}
closeable - the object to close, may be null or already closedpublic static byte[] toByteArray(InputStream in)
in - 输入流nullpublic static byte[] toByteArray(InputStream in, int size)
in - 输入流size - 读取长度,不能小于0public static byte[] toByteArray(Reader reader)
Reader的内容转为字节数组,否转换异常则返回nullreader - read fromnull,否则返回字节数组public static byte[] toByteArray(Reader reader, String encoding)
Reader的内容转为字节数组,否转换异常则返回nullreader - read fromencoding - 编码null,否则返回字节数组public static byte[] toByteArray(Reader reader, Charset encoding)
Reader的内容转为字节数组,否转换异常则返回nullreader - read fromencoding - 编码null,否则返回字节数组public static String toString(InputStream in)
public static String toString(InputStream in, String encoding)
public static String toString(InputStream in, Charset encoding)
public static int copy(InputStream in, OutputStream out)
in - 输入流out - 输出流public static long copyLarge(InputStream in, OutputStream out)
in - 输入流out - 输出流public static long copyLarge(InputStream in, OutputStream out, byte[] buffer)
in - 输入流out - 输出流buffer - 缓冲区public static boolean copy(InputStream in, Writer writer)
Writer字符内容,使用系统默认编码。in - 字节输入流writer - 字符输出流true,否则返回falsepublic static boolean copy(InputStream in, Writer writer, String encoding)
Writer字符内容,使用系统默认编码。in - 字节输入流writer - 字符输出流encoding - 字符编码,如果为空则使用平台默认编码true,否则返回falsepublic static boolean copy(InputStream in, Writer writer, Charset encoding)
Writer字符内容,使用系统默认编码。in - 字节输入流writer - 字符输出流encoding - 字符编码,如果为空则使用平台默认编码true,否则返回falsepublic static int copy(Reader reader, Writer writer)
reader - 字符输入流writer - 字符输出流public static long copyLarge(Reader reader, Writer writer)
reader - 字符输入流writer - 字符输出流public static long copyLarge(Reader reader, Writer writer, char[] buffer)
reader - 字符输入流writer - 字符输出流buffer - 缓冲区public static boolean copy(Reader reader, OutputStream out)
reader - 字符输入流out - 字节输出流true,否则返回falsepublic static boolean copy(Reader reader, OutputStream out, String encoding)
reader - 字符输入流out - 字节输出流encoding - 编码true,否则返回falsepublic static boolean copy(Reader reader, OutputStream out, Charset encoding)
reader - 字符输入流out - 字节输出流encoding - 编码true,否则返回falsepublic static String md5Hex(InputStream in)
in - 输入流public static String sha1Hex(FileInputStream in)
in - 输入流public static List<String> readLines(InputStream in)
in - 待读取的流public static List<String> readLines(InputStream in, Charset charset)
in - 待读取的流charset - 字符编码Copyright © 2017. All rights reserved.