Android异常记录-HttpClient中文名称乱码

来源:互联网 发布:弹弓淘宝网店铺 编辑:程序博客网 时间:2024/05/17 09:04

最近做Android的文件上传与下载,记录下问题(Apach Tomcat6.0做服务器)

1.URL有中文访问不到,上传路径用如下方法可以完美解决,但下载还是不行,比如链接http://localhost:8080/upload/files/测试.txt,资源定位不到????

/**  *解决中文文件名乱码  */  public class CustomFilePart extends FilePart {       public CustomFilePart(String filename, File file)               throws FileNotFoundException {           super(filename, file);       }         protected void sendDispositionHeader(OutputStream out) throws IOException {           super.sendDispositionHeader(out);           String filename = getSource().getFileName();           if (filename != null) {               out.write(EncodingUtil.getAsciiBytes(FILE_NAME));               out.write(QUOTE_BYTES);               out.write(EncodingUtil.getBytes(filename, "utf-8"));               out.write(QUOTE_BYTES);           }       }   }  调用try{Part [] parts = {//new FilePart("uploadFile",new File(filePath))new CustomFilePart(file.getName(),file)  };

更多请参考原文 http://blog.csdn.net/sxtyxdljbsg/article/details/6446861#

2.项目部署

经过以下步骤,可以顺利部署在tomact的webapp下,方便url访问文件,务必记住相关外Jar包也要放入tomcat的lib目录下





0 0