//程序没有什么问题
serverFilePath=路径+文件名
File file=new File(serverFilePath);
formitem.write(file);但是中文名都是乱码,文件里的内容是正确的,我JSP页面都设置了utf-8
是不是我的文件名还要在转换一下?

解决方案 »

  1.   

    是否用的commons-fileupload?如果是的话,使用Fileupload类的setHeaderEncoding("utf-8")
    另外,commons-fileupload-1.1使用resquest.setCharsetEnconding("utf-8")也可以
      

  2.   

    补充一下 如果你的linux服务器使用的默认编码是gbk的话 可以讲你的文件名转换一下
    new String(fileName.getByte("gbk"),"utf-8")
      

  3.   

    import org.apache.commons.io.FileUtils; 
    imageFileName:文件名String imageName = imageFileName.substring(0, imageFileName
    .lastIndexOf("."))
    + UUID.randomUUID().toString();
    // 上传:
    String s=imageName
    + imageFileName.substring(imageFileName.lastIndexOf("."), imageFileName.length();FileUtils.copyFile(image, new File(path+ "uipconfig/fileUpload",new String(s
    .getByte("gbk"),"utf-8")))); 我给文件名加上那种 转码了但是还是不行。