Java localized filenames

前端 未结 4 1265
轮回少年
轮回少年 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:46

    What gustafc says is correct, but it doesn't get you where you want to be. RFC 2231 allows you to use an alternative format for non-ASCII Content-Type and Content-Disposition parameters, but not all browsers support it. The way that's most likely to work, unfortunately, is to ignore what RFC 2183 says and use RFC 2047 encoded-words in the response:

    response.addHeader("Content-Disposition", "attachment; " +
        "filename=\"" + MimeUtility.encodeWord(fileName, "utf-8", "Q") + "\"");
    

    Note that this may not work for all browsers. Some variants of IE require that you URL-encode the value instead:

    response.addHeader("Content-Disposition",
        "attachment; filename=" + URLEncoder.encode(filename, "utf-8"));
    

提交回复
热议问题