日期:2014-05-16 浏览次数:20403 次
public static String toUtf8String(String s) { StringBuffer sb = new StringBuffer(); for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); if (c >= 0 && c <= 255) { sb.append(c); } else { byte[] b; try { b = Character.toString(c).getBytes("utf-8"); } catch (Exception ex) { System.out.println(ex); b = new byte[0]; } for (int j = 0; j < b.length; j++) { int k = b[j]; if (k < 0) { k += 256; } sb.append("%" + Integer.toHexString(k). toUpperCase()); } } } return sb.toString(); } String fileName=request.getParameter("filename"); String contextPath=request.getSession().getServletContext().getRealPath(""); String filePath=contextPath+"//"+InitParameter.getUploadFile_Path()+"//"; File file=new File(filePath+fileName); String fileName1=toUtf8String(fileName); response.setContentType("application/octet-stream"); response.setContentType("application/OCTET-STREAM;charset=UTF-8"); response.setHeader("Content-Disposition", "attachment;filename="+fileName1);