Blog信息 |
blog名称:小鸟吹烟 日志总数:157 评论数量:424 留言数量:-1 访问次数:1263275 建立时间:2006年10月23日 |

| |
[jsp]解决javamail附件乱码问题 原创空间, 心得体会, 软件技术
tone 发表于 2007/2/9 10:13:57 |
今天发现收到的邮件附件打开后乱码,所以使用了另外一种方式保存附件解决了 此一问题.
private void saveFile(String fileName, InputStream in) throws IOException { String dir = getAttachPath(); if(dir == null || dir.equals("")) setAttachPath("E:\\testMail\\"); File storefile = new File(getAttachPath()+fileName); System.out.println("file's path: "+storefile.toString());
BufferedOutputStream bos = null; BufferedInputStream bis = null; try{ bos = new BufferedOutputStream(new FileOutputStream(storefile)); bis = new BufferedInputStream(in); int c; while((c=bis.read()) != -1){ bos.write(c); bos.flush(); } }catch(Exception exception){ throw new RuntimeException("文件保存失败!"); }finally{ bos.close(); bis.close(); } } |
|
|