[問題] javamail已設big5但還是亂碼,solaris系統

看板java作者 (累)時間11年前 (2014/02/14 10:48), 編輯推噓1(106)
留言7則, 4人參與, 最新討論串1/1
程式內容是為了讀檔案,然後依檔案內容發送給不同寄件者與mail內容 程式內容如下,有人可以幫忙解答嗎??謝謝了 String fromLang = "BIG5"; String strSubject; //讀入檔案 String inFile = "sendcontent.txt"; try{ File readfile = new File(inFile); if (readfile.exists()) { System.setProperty( "mail.mime.charset", "big5" ); // Create a default MimeMessage object. MimeMessage message = new MimeMessage(session); BufferedReader input = new BufferedReader(new FileReader(readfile)); String strContent; // Create the message part BodyPart messageBodyPart = new MimeBodyPart(); // Create a multipar message Multipart multipart = new MimeMultipart(); while ((strContent = input.readLine()) != null) { while (!strContent.equals("END") && strContent != null) { String[] strArry = strContent.split(":"); //收件者 if (strArry[0].equals("TO")) { // Set To: header field of the header. to = strArry[1]; message.addRecipient(Message.RecipientType.TO, new InternetAddress(to)); } //主旨、寄件者 else if (strArry[0].equals("SUBJECT")) { // Set From: header field of the header. InternetAddress from = new InternetAddress(fromAdd, fromName, fromLang); message.setFrom(from); // Set Subject: header field message.setSubject(strArry[1], "big5"); //message.setSubject(MimeUtility.encodeText(strArry[1], "big5", "B")); //message.setHeader("Subject", MimeUtility.encodeText(strArry[1], "big5", "B")); //message.setSubject(MimeUtility.encodeText(message.getSubject(), "big5", "B")); System.out.println(strArry[1]); } //本文內容 else if (strArry[0].equals("TEXT")) { messageBodyPart = new MimeBodyPart(); //* Send the actual HTML message, as big as you like(HTML) StringBuffer mailText = new StringBuffer(""); mailText.append(strArry[1]); messageBodyPart.setContent(mailText.toString(), "text/html;charset=BIG5"); multipart.addBodyPart(messageBodyPart); } //附件 else if (strArry[0].equals("ATTFILE")) { messageBodyPart = new MimeBodyPart(); String filename = strArry[1]; DataSource source = new FileDataSource(filename); messageBodyPart.setDataHandler(new DataHandler(source)); messageBodyPart.setFileName(MimeUtility.encodeText(filename,"BIG5","B")); multipart.addBodyPart(messageBodyPart); } strContent = input.readLine(); } message.setContent(multipart); // Send message Transport.send(message); message = new MimeMessage(session); multipart = new MimeMultipart(); } System.out.println("END結束"); } }catch (MessagingException mex) { mex.printStackTrace(); }catch (Exception e) { e.printStackTrace(); } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 115.80.39.159

02/14 11:16, , 1F
你file 上來就編碼不對了吧, 讀檔可以設定編碼的.
02/14 11:16, 1F

02/14 11:46, , 2F
推樓上,另外這種問題最好補 client 環境 & 設定
02/14 11:46, 2F

02/14 15:50, , 3F
這種大概是開發都在windows環境~然後一上線就有問題
02/14 15:50, 3F

02/15 01:01, , 4F
unix上JAVAAP讀檔的預設編碼=locale的設定.
02/15 01:01, 4F

02/15 12:21, , 5F
s大請問一上線就有問題是可能什麼樣的問題啊?
02/15 12:21, 5F

02/15 12:23, , 6F
L大,在solaris上語系設為BIG5即解決了,謝謝!!
02/15 12:23, 6F

02/16 08:38, , 7F
基本上,並不建議動locale,即跑該JAVA AP的ENV的LOCALE
02/16 08:38, 7F
文章代碼(AID): #1I_OFmUR (java)
文章代碼(AID): #1I_OFmUR (java)