Java localized filenames

前端 未结 4 1336
轮回少年
轮回少年 2021-02-09 14:05

How can i set localized filenames in java.Currently everytime i click on a localized file having a non-ascii filename in my application, the windows save dialog box pops out, bu

4条回答
  •  悲哀的现实
    2021-02-09 14:30

    I faced similar problems with filenames containing greek characters.I used the code provided in the answer above (my thanks to dkarp) combined with detecting which browser is used. this is the result:

    String user_agent = request.getHeader("user-agent");
    boolean isInternetExplorer = (user_agent.indexOf("MSIE") > -1);
    if (isInternetExplorer) {
        response.setHeader("Content-disposition", "attachment; filename=\"" + URLEncoder.encode(filename, "utf-8") + "\"");
    } else {
        response.setHeader("Content-disposition", "attachment; filename=\"" + MimeUtility.encodeWord(filename) + "\"");
    }
    

    I tested it with firefox 3.6 , chrome 10.0 and Internet Explorer 8 and it seems to work fine.

提交回复
热议问题