Commit 941fcaac authored by Quxl's avatar Quxl

x

parent 762d5473
......@@ -14,7 +14,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
......@@ -363,18 +362,23 @@ public class FileUtil {
public static byte[] streamToBytes(InputStream instream) {
byte[] bytes = null;
ByteArrayOutputStream baos = null;
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream(102400);
baos = new ByteArrayOutputStream(102400);
byte[] b = new byte[102400];
int n;
while ((n = instream.read(b)) != -1) {
baos.write(b, 0, n);
}
instream.close();
baos.close();
bytes = baos.toByteArray();
} catch (Exception e) {
throw new FileUtilException("将输入流转换为字节数组异常", e);
} finally {
try {
baos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return bytes;
}
......@@ -549,30 +553,6 @@ public class FileUtil {
}
/**
*
* @Title: inputStreamToFile
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param: @param ins
* @param: @param file
* @return: void
* @throws
*/
public static void inputStreamToFile(InputStream ins,File file) {
try {
OutputStream os = new FileOutputStream(file);
int bytesRead = 0;
byte[] buffer = new byte[8192];
while ((bytesRead = ins.read(buffer, 0, 8192)) != -1) {
os.write(buffer, 0, bytesRead);
}
os.close();
ins.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static Object fileToObject(File file) {
FileInputStream fis = null;
ObjectInputStream ois = null;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment