public class IoUtils extends Object
| 构造器和说明 |
|---|
IoUtils() |
| 限定符和类型 | 方法和说明 |
|---|---|
static void |
cleanDirectory(File directory)
清理目录下的内容.
|
static void |
closeQuietly(Closeable closeable)
Close closable object quietly.
|
static void |
closeQuietly(HttpURLConnection connection)
Close http connection quietly.
|
static void |
closeQuietly(InputStream input) |
static void |
closeQuietly(OutputStream output) |
static long |
copy(InputStream input,
OutputStream output)
Copy data.
|
static long |
copy(Reader input,
Writer output)
Copy data.
|
static void |
copyFile(String source,
String target)
Copy File.
|
static void |
delete(File fileOrDir)
Delete file or dir.
|
static boolean |
isGzipStream(byte[] bytes)
Judge whether is Gzip stream.
|
static List<String> |
readLines(Reader input)
Read lines.
|
static String |
toString(InputStream input,
String encoding)
To string from stream.
|
static String |
toString(Reader reader)
To string from reader.
|
static byte[] |
tryDecompress(byte[] raw)
Try decompress by GZIP from byte array.
|
static byte[] |
tryDecompress(InputStream raw)
Try decompress by GZIP from stream.
|
static void |
writeStringToFile(File file,
String data,
String encoding)
Write string to a file.
|
public static byte[] tryDecompress(InputStream raw) throws IOException
raw - compress streamIOException - exceptionpublic static byte[] tryDecompress(byte[] raw)
throws Exception
raw - compressed byte arrayException - exceptionpublic static void writeStringToFile(File file, String data, String encoding) throws IOException
file - filedata - stringencoding - encoding of stringIOException - io exceptionpublic static List<String> readLines(Reader input) throws IOException
input - readerIOException - io exceptionpublic static String toString(InputStream input, String encoding) throws IOException
input - streamencoding - charset of streamIOException - io exceptionpublic static String toString(Reader reader) throws IOException
reader - readerIOException - io exceptionpublic static long copy(Reader input, Writer output) throws IOException
input - sourceoutput - targetIOException - io exceptionpublic static long copy(InputStream input, OutputStream output) throws IOException
input - sourceoutput - targetIOException - io exceptionpublic static void delete(File fileOrDir) throws IOException
If is dir, clean directory, do not delete dir.
If is file, delete file.
fileOrDir - file or dirIOException - io exceptionpublic static void cleanDirectory(File directory) throws IOException
directory - directoryIOException - io exceptionpublic static void copyFile(String source, String target) throws IOException
source - source file pathtarget - target file pathIOException - io exceptionpublic static boolean isGzipStream(byte[] bytes)
bytes - byte arraypublic static void closeQuietly(HttpURLConnection connection)
connection - http connectionpublic static void closeQuietly(InputStream input)
public static void closeQuietly(OutputStream output)
public static void closeQuietly(Closeable closeable)
closeable - http connectionCopyright © 2018–2021 Alibaba Group. All rights reserved.