以前写的一个从接收邮件的小程序,今天正好在练习写一个类似outlook的客户端邮件程序,突然发现之前的那个程序有点问题:
先前的程序(从网络读取的附件保存到本地):
BufferedInputStream read=new BufferedInputStream(part.getInputStream());
BufferedOutputStream out=new BufferedOutputStream(new FileOutputStream(file));
System.out.println("文件大小为:"+read.available()/1024.0+"KB");
int count=0;
while(true){
count=read.read(b);
if(count<=0){
break;
}
out.write(b);
}
out.close();
read.close();
改为
将out.write(b)-->out.write(b,0,count);