请教关于JavaMail中文乱码的问题 试试以下语句:new String(sourceStr.getBytes("8859_1"), "GBK")如果不行,你需要了解sourceStr到底是什么charset! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用我下面给你的方法得到福建名,然后如下处理就可以了String filename= new String(getISOFileName(part).getBytes("ISO-8859-1"),"gb2312");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()); } } i really want to know 如何更好的学习!!!!! 初学者问个有关对象初始化的问题,谢谢 初始化这方面的问题 java中怎样使用游标?急!!! 一个字节数组是否可以发送两个不同的对象? jar文件是怎么回事 java中怎样读取应用程序名 有关ClassPath 的问题 多线程问题请教 怎么用记事本运行java 请高手指教! 送高分!一些关于SCJP考试的问题!请已经通过考试的大侠们帮忙!
就可以了
String filename= new String(getISOFileName(part).getBytes("ISO-8859-1"),"gb2312");
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());
}
}