| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- package cn.com.goldenwater.dcproj.util;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.InputStream;
- import java.io.OutputStream;
- public class IoUtil {
- /**
- * 写出
- *
- * @param file
- * @param out
- */
- public static void writeFile(File file, OutputStream out) {
- ;
- try (FileInputStream fs = new FileInputStream(file)) {
- //循环写入输出流
- byte[] b = new byte[1024 * 8];
- int len;
- while ((len = fs.read(b)) > 0) {
- out.write(b, 0, len);
- }
- } catch (Exception e) {
- throw new RuntimeException("流写出错误");
- } finally {
- close(out);
- }
- }
- /**
- * 关流
- */
- public static void close(InputStream is) {
- if (is != null) {
- try {
- is.close();
- is = null;
- } catch (Exception e2) {
- throw new RuntimeException("关闭流失败");
- }
- }
- }
- /**
- * 关流
- */
- public static void close(OutputStream os) {
- if (os != null) {
- try {
- os.close();
- os = null;
- } catch (Exception e2) {
- throw new RuntimeException("关闭流失败");
- }
- }
- }
- /**
- * 关流
- */
- public static void close(InputStream is, OutputStream os) {
- if (is != null) {
- try {
- is.close();
- is = null;
- } catch (Exception e2) {
- throw new RuntimeException("关闭流失败");
- }
- }
- if (os != null) {
- try {
- os.close();
- os = null;
- } catch (Exception e2) {
- throw new RuntimeException("关闭流失败");
- }
- }
- }
- }
|