javamail附件中文名的奇怪问题(不是iso8859 -> gb2312那么简单哦)!! 没有人帮忙吗?分不够再说,帮我搞定先好吗?多谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你可以直接从Content-Disposition中获取文件名,下面是我写的一个函数不知是否有用: */ public static String getChineseFileName(Part body){ return ToolKit.toChinese(getISOFileName(body)); } /* @从BodyPart中提取使用ISO-8859-1编吗的文件名 @因为BodyPart.getFilename()过程已经对文件名作了一次编码,有时不能直接使用 */ public static String getISOFileName(Part body){ //设置一个标志,判断文件名从Content-Disposition中获取还是从Content-Type中获取 boolean flag=true; if(body==null){ return null; } String[] cdis; try{ cdis=body.getHeader("Content-Disposition"); } catch(Exception e){ return null; } if(cdis==null){ flag=false; } if(!flag){ try{ cdis=body.getHeader("Content-Type"); } catch(Exception e){ return null; } } if(cdis==null){ return null; } if(cdis[0]==null){ return null; } //从Content-Disposition中获取文件名 if(flag){ int pos=cdis[0].indexOf("filename="); if(pos<0){ return null; } //如果文件名带引号 if(cdis[0].charAt(cdis[0].length()-1)=='"'){ return cdis[0].substring(pos+10,cdis[0].length()-1); } return cdis[0].substring(pos+9,cdis[0].length()); } else{ int pos=cdis[0].indexOf("name="); if(pos<0){ return null; } //如果文件名带引号 if(cdis[0].charAt(cdis[0].length()-1)=='"'){ return cdis[0].substring(pos+6,cdis[0].length()-1); } return cdis[0].substring(pos+5,cdis[0].length()); } } 高分请假高手怎样用displagtag1.1实现分页?谢谢! 我痛恨着SUN 我是个新手,我有个值20分的问题,不知道有人要没? 帮我看看错哪 关于Myeclipse问题(初级) 请教一个Applet的问题 我是菜鸟,请帮助我。编译JAVA程序时,“e.hasMore Elements()”出错,不明白! 我在jbuilder5中作了个session bean,make时出现如下错误,为什么? applet是否可以操作cookie? 渣新刚注册csdn求教各位大神一个简单的二分法问题!谢谢!非伸手党.. 服务器上文件的下载??? 关于在JAVA中使用数据连接的问题
*/
public static String getChineseFileName(Part body){
return ToolKit.toChinese(getISOFileName(body));
} /*
@从BodyPart中提取使用ISO-8859-1编吗的文件名
@因为BodyPart.getFilename()过程已经对文件名作了一次编码,有时不能直接使用
*/
public static String getISOFileName(Part body){
//设置一个标志,判断文件名从Content-Disposition中获取还是从Content-Type中获取
boolean flag=true;
if(body==null){
return null;
}
String[] cdis;
try{
cdis=body.getHeader("Content-Disposition");
}
catch(Exception e){
return null;
}
if(cdis==null){
flag=false;
}
if(!flag){
try{
cdis=body.getHeader("Content-Type");
}
catch(Exception e){
return null;
}
}
if(cdis==null){
return null;
}
if(cdis[0]==null){
return null;
}
//从Content-Disposition中获取文件名
if(flag){
int pos=cdis[0].indexOf("filename=");
if(pos<0){
return null;
}
//如果文件名带引号
if(cdis[0].charAt(cdis[0].length()-1)=='"'){
return cdis[0].substring(pos+10,cdis[0].length()-1);
}
return cdis[0].substring(pos+9,cdis[0].length());
}
else{
int pos=cdis[0].indexOf("name=");
if(pos<0){
return null;
}
//如果文件名带引号
if(cdis[0].charAt(cdis[0].length()-1)=='"'){
return cdis[0].substring(pos+6,cdis[0].length()-1);
}
return cdis[0].substring(pos+5,cdis[0].length());
}
}