分类:
2008-09-12 13:09:47
package com.syj.util;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.StringReader;
import java.util.Arrays;
/**
*
* Title:IO工具类
*
* Description:常用的IO操作封装
*
* Copyright: 转载请注明出处 * @date Jun 15, 2008 4:37:58 PM
*/
public class IOUtil {
/**
* 缓冲区大小 1MB
*/
private static final int BUFFER_SIZE = 1024 * 1024;
/**
*
* Description: 将输入流输出到输出流
*
* @param in
* 输入流
* @param out
* 输出流
* @param bufferSize
* 缓冲区大小
* @throws IOException
* @mail * @since:Jun 15, 2008 4:52:41 PM
*/
public static ByteArrayOutputStream readFileToByteStream(File file)
throws IOException {
FileInputStream fis = null;
ByteArrayOutputStream bos = null;
try {
fis = new FileInputStream(file);
bos = new ByteArrayOutputStream();
in2OutStream(fis, bos, BUFFER_SIZE);
} finally {
if (fis != null)
fis.close();
}
return bos;
}
/**
*
* Description:读取文件返回字节数组
*
* @param file
* 文件
* @return 字节数组
* @throws IOException
* @mail * @since:Jun 15, 2008 5:46:32 PM
*/
public static String readFileToString(File file) throws IOException {
StringBuffer sb = null;
BufferedReader in = null;
try {
in = new BufferedReader(new FileReader(file));
sb = new StringBuffer();
for (String line; (line = in.readLine()) != null;) {
sb.append(line + "\r\n");
}
} finally {
if (in != null)
in.close();
}
return sb.toString();
}
/**
*
* Description:复制文件
*
* @param src
* 源文件
* @param dest
* 目标文件
* @param cover
* 是否覆盖
* @throws IOException
* @mail
【责编:landy】