如题,中文文件名乱码该如何解决? if (uploads != null)
{
File dir = new File(dirName);
if(!dir.isDirectory())
dir.mkdirs();
int i = 0;
for (; i < uploads.size(); i++)
{
java.io.InputStream is = new java.io.FileInputStream(uploads.get(i));
java.io.OutputStream os = new java.io.FileOutputStream(
dirName + }new String(fileNames.get(i).getBytes("gb2312"),"iso-8859-1"));
byte buffer[] = new byte[8192];
int count = 0;
while ((count = is.read(buffer)) > 0)
{
os.write(buffer, 0, count);
}
os.close();
is.close();
}
{
File dir = new File(dirName);
if(!dir.isDirectory())
dir.mkdirs();
int i = 0;
for (; i < uploads.size(); i++)
{
java.io.InputStream is = new java.io.FileInputStream(uploads.get(i));
java.io.OutputStream os = new java.io.FileOutputStream(
dirName + }new String(fileNames.get(i).getBytes("gb2312"),"iso-8859-1"));
byte buffer[] = new byte[8192];
int count = 0;
while ((count = is.read(buffer)) > 0)
{
os.write(buffer, 0, count);
}
os.close();
is.close();
}
这里有个问题,网上经常有人将编码格式改称gbk或者是gb2312,
不过为了国际化和通用性,我建议还是用UTF-8编码格式。
毕竟现在的开发工具大部分都是国外的,对UTF-8的支持到位。
同时国际化也方便。 你这里struts上传文件用的是gb2312编码方式,那你就
new String(filename.getBytes("GB2312"),"UTF-8");
代码里改成 java.io.OutputStream os = new java.io.FileOutputStream(
dirName + new String(fileNames.get(i).getBytes("GBK"),"utf-8"));
中文文件名还是?