JSP中,中文文件名的文件删除,说文件不存在呢?(50分)

  • 主题发起人 cornermoss
  • 开始时间
C

cornermoss

Unregistered / Unconfirmed
GUEST, unregistred user!
tomcat4.18+JDK1.4.1+win98下
一中文文件连接如下:
http://127.0.0.1/ylnet/uploads/mail/2003031215065738740-函数,1.txt
可以正常访问
但是我程序中删除
//其中affix即为2003031215065738740-函数,1.txt
File AffixF=new File(affixUpdir+affix);
try
{ if (AffixF.exists())
{AffixF.delete();
return 1;
}
else
return -4;

}
catch(Exception e) { System.err.println("Err!Del Affix:"+e.getMessage());
return -5;
}
这样的返回值为-4,说文件不存在呢?
但是如果affix不包含中文的话,能够正常删除的。
谢谢各位指点一下吧?不胜感激^_*
原贴:http://expert.csdn.net/expert/Topicview1.asp?id=1521736
 
你应该把文件名转换成中文,你增加strToGBK函数,测试看看
//转换成中文
public String strToGBK(String str) {
try {
String temp_p=str;
byte[] temp_t=temp_p.getBytes("ISO8859_1");
String temp=new String(temp_t,"gb2312");
return temp;
} catch(Exception e) {
return "null";
}
}
File AffixF=new File(strToGBK(affixUpdir+affix));
try
{ if (AffixF.exists())
{AffixF.delete();
return 1;
}
else
return -4;

}
catch(Exception e) { System.err.println("Err!Del Affix:"+e.getMessage());
return -5;
}
 
谢谢李崇文,问题解决
我的是
//把表单中提交的中文进行转换 //入库前也要转换
public String toGB(String iso)
{ String gb=null;
if (iso != null)
{ try { gb=new String(iso.getBytes("ISO8859_1"),"GB2312");
}
catch (Exception e) { gb=null;
}
}
return gb;
}
 
多人接受答案了。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
723
import
I
顶部