2017-05-31 103 views
0

我有一個Web服務提供者(Java),它將.doc文件導入到NotesDocument。在名稱中帶有俄語字符的文件會出現問題 - 它們未正確傳輸。 例如,如果filename將等於Безымянный.doc,則它將被轉移爲Áåçûìÿííûé.doc在IBM Notes文檔中附件的名稱字符集/編碼

File directory = new File("C:\\Attachments 1C"); 
String filename = "Безымянный.doc" 
String path = directory + "\\" + filename; 
Stream outStream = sess.createStream(); 
sess.setConvertMIME(true); 
MIMEEntity body = newDoc.createMIMEEntity("rtBody"); 

Stream inStream = sess.createStream(); 
if (inStream.open(path, "binary")) { 
    if (inStream.getBytes() > 0) { 
     do { 
      byte[] buffer = inStream.read(32767); 
      outStream.write(buffer); 
     } while (!inStream.isEOS()); 
     inStream.close(); 

     MIMEEntity child = body.createChildEntity(); 

     String fileSuffix = path.substring(path.lastIndexOf(".")+1); 

     child.setContentFromBytes(outStream, fileSuffix, MIMEEntity.ENC_IDENTITY_BINARY); 

     MIMEHeader header = child.createHeader("Content-Disposition"); 
     header.setHeaderVal("attachment; filename=\"" + filename + "\""); 
     header = child.createHeader("Content-ID"); 
     header.setHeaderVal(path); 
     outStream.truncate(); 
    }else 
     return "empty file"; 
}else 
    return "couldn't open the file"; 

如何解決這個問題?

回答

0

這個標準並不是最終的,行爲將取決於使用的瀏覽器。請參閱this previous question on StackOverflow的問題和答案以獲取詳細說明以及有關各種瀏覽器可以使用的信息。

+0

我並不在這種情況下瀏覽器。該文件附加到IBM Notes環境中的NotesDocument。 – klendathu

+1

我試過這個:String dispositionFileName = URLEncoder.encode(filename,「UTF-8」) - 不起作用。 – klendathu

0

問題是由編碼使用MimeUtility名解決了(別人不工作):

String filenameEndoded = MimeUtility.encodeText(filename,"Cp1251","B");