当前位置: 技术问答>java相关
问一个通过javamail保存附件的问题
来源: 互联网 发布时间:2015-08-12
本文导语: 我写了段程序用来存放邮件中的附件 1: File filename = new File(part.getFileName()); 2: FileOutputStream myFileoutputstream = new FileOutputStream(filename); 3: int chunk = part.getSize(); 4: byte [] buffer; 5: buffer = new byte[chunk]; 6...
我写了段程序用来存放邮件中的附件
1: File filename = new File(part.getFileName());
2: FileOutputStream myFileoutputstream = new FileOutputStream(filename);
3: int chunk = part.getSize();
4: byte [] buffer;
5: buffer = new byte[chunk];
6: InputStream instream;
7: instream = part.getInputStream();
8: instream.read(buffer,0,chunk);
9: myFileoutputstream.write(buffer,0,chunk);
10:instream.close();
11:myFileoutputstream.close();
我的附件大小为 2,508,822
邮件大小为 3,435,010
但是我在第3行取出来的附件的值为什么是3,433,127?
另外最后经过不断的测试,发现问题出在第8行,请问怎么解决呀?
1: File filename = new File(part.getFileName());
2: FileOutputStream myFileoutputstream = new FileOutputStream(filename);
3: int chunk = part.getSize();
4: byte [] buffer;
5: buffer = new byte[chunk];
6: InputStream instream;
7: instream = part.getInputStream();
8: instream.read(buffer,0,chunk);
9: myFileoutputstream.write(buffer,0,chunk);
10:instream.close();
11:myFileoutputstream.close();
我的附件大小为 2,508,822
邮件大小为 3,435,010
但是我在第3行取出来的附件的值为什么是3,433,127?
另外最后经过不断的测试,发现问题出在第8行,请问怎么解决呀?
|
public String[] getpart(int i){
String[] partname=null;
String m_uploadpath="c:\upload\";
try{
folder.open(Folder.READ_WRITE);//READ_ONLY为打开方式
message=folder.getMessages();
Multipart mp = (Multipart)message[i].getContent();
int m=mp.getCount();
partname = new String[m-1];
for (int j=0;j
String[] partname=null;
String m_uploadpath="c:\upload\";
try{
folder.open(Folder.READ_WRITE);//READ_ONLY为打开方式
message=folder.getMessages();
Multipart mp = (Multipart)message[i].getContent();
int m=mp.getCount();
partname = new String[m-1];
for (int j=0;j