2020-06-10 15:50:58
浏览数 (1)
代码示例
代码语言:javascript
复制package com.simple.util.io;
import org.apache.commons.io.IOUtils;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
/**
* @program: simple_tools
* @description:
* @author: Mr.chen
* @create: 2020-06-09 10:00
**/
public class IOUtil {
/**
*
* @param is
* @return
*/
public static String ioToString(InputStream is) {
try {
return IOUtils.toString(is, "utf-8");
} catch (IOException e) {
e.printStackTrace();
}
return "";
}
/**
*
* @param xml
* @param out
*/
public static void write(String xml, OutputStream out) {
try {
IOUtils.write(xml, out, "utf-8");
} catch (IOException e) {
e.printStackTrace();
}
}
/**
*
* @param obj
*/
public static void close(Object obj) {
try {
if (obj instanceof InputStream) {
((InputStream) obj).close();
}
if (obj instanceof OutputStream) {
((OutputStream) obj).close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}