日期:2014-05-17 浏览次数:20678 次
//上面代码省略
File saveFile = new File(savePath + name + extName);
InputStream ipt=bodyPart.getInputStream();
OutputStream out=new FileOutputStream(saveFile);
int count = bodyPart.getSize();
System.out.println(count)
long start = System.currentTimeMillis();
int b = 0;
byte[] buffer = new byte[count];
while (b != -1){
b = ipt.read(buffer);
out.write(buffer);
}
ipt.close();
out.close();
out.flush();
long end = System.currentTimeMillis();
System.out.println("耗时:" + (end - start) + "毫秒");
public static void main(String[] args) throws IOException {
long start = System.currentTimeMillis();
BufferedInputStream inBuff = null;
BufferedOutputStream outBuff = null;
try {
// 新建文件输入流并对它进行缓冲
inBuff = new BufferedInputStream(new FileInputStream(
"D:\\soft\\apache-tomcat-6.0.20.exe"));
// 新建文件输出流并对它进行缓冲
outBuff = new BufferedOutputStream(new FileOutputStream(
"D:\\test\\test"));
// 缓冲数组
byte[] b = new byte[1024];
int len;
while ((len = inBuff.read(b)) != -1) {
outBuff.write(b, 0, len);
}
// 刷新此缓冲的输出流
outBuff.flush();
} finally {
// 关闭流
if (inBuff != null)
inBuff.close();
if (outBuff != null)
outBuff.close();
}
long end = System.currentTimeMillis();
System.out.println("耗时:" + (end - start) + "毫秒");
}