问题描述
郁闷啦,做个邮件客户端不是这报错就是那报错,我在火弧下发送邮件,附件名正常,但当我到了IE下时,附件名就变成了路径名+附件名了,我用转义字符也不行,大侠们有没有什么简单快捷的方法啊?在线等待贴一下我保存附件的代码:publicvoidsaveAttachMent(Partpart)throwsException{StringfileName="";if(part.isMimeType("multipart/*")){Multipartmp=(Multipart)part.getContent();for(inti=0;i<mp.getCount();i++){BodyPartmpart=mp.getBodyPart(i);Stringdisposition=mpart.getDisposition();if((disposition!=null)&&((disposition.equals(Part.ATTACHMENT))||(disposition.equals(Part.INLINE)))){fileName=mpart.getFileName();if(fileName.toLowerCase().indexOf("utf-8")!=-1){fileName=MimeUtility.decodeText(fileName);if(fileName.lastIndexOf("\")>0){fileName.replace("\","_");}}if(fileName.toLowerCase().indexOf("gb2312")!=-1){fileName=MimeUtility.decodeText(fileName);if(fileName.lastIndexOf("\")>0){fileName.replace("\","_");}}System.out.println(fileName);saveFile(fileName,mpart.getInputStream());}elseif(mpart.isMimeType("multipart/*")){saveAttachMent(mpart);}else{fileName=mpart.getFileName();if((fileName!=null)&&(fileName.toLowerCase().indexOf("utf-8")!=-1)){fileName=MimeUtility.decodeText(fileName);if(fileName.lastIndexOf("\")>0){fileName.replace("\","_");}saveFile(fileName,mpart.getInputStream());}elseif((fileName!=null)&&(fileName.toLowerCase().indexOf("gb2312")!=-1)){fileName=MimeUtility.decodeText(fileName);if(fileName.lastIndexOf("\")>0){fileName.replace("\","_");}saveFile(fileName,mpart.getInputStream());}}}}elseif(part.isMimeType("message/rfc822")){saveAttachMent((Part)part.getContent());}}
解决方案
解决方案二:
BodyPartbp2=newMimeBodyPart();DataSourceds=newFileDataSource(file);bp2.setDataHandler(newDataHandler(ds));bp2.setFileName(MimeUtility.encodeWord("文件名.xls"),"gb2312",null));
解决方案三:
我用了截取字符的方法好了,不过还是要谢谢你的回贴