简体   繁体   中英

How to read non-English characters in filename, using Java programme

I'm trying to read mail in my outbox which usually contains one attached pdf file. If the pdf file name contains English characters, the function below works fine. But if the file name contains any non-English character (for example, filename1(chinesecharacter).pdf ) my function is not able to read it. Can anybody tell me what changes I need to make in my function?

Just simply check the ASCII (or Unicode?) values against the range(s) of values with English characters. Every character corresponds to a number in its character set.

Or you could create an array of all English characters, and check it against that. There may also be an API function in Java.

This line indicates you might have a problem decoding non-ISO 8859 character sets, eg UTF-8, due to the weak handling of RFC2822 encoded file names:

if(fileName.startsWith("=?iso-8859"))
{
  String strFolder = strFolderName.substring(strFolderName.lastIndexOf("/")+1,
                                             strFolderName.length());
  fileName = strFolder + ".pdf";
}

http://en.wikipedia.org/wiki/MIME#Encoded-Word

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM