JAVA关于java.io.unsupportedencodingexception解决方法

来源:互联网 发布:php 命名空间 大小写 编辑:程序博客网 时间:2024/05/16 14:47

本人是在获取邮件附件Content时遇到的错误 也适用于其他情况获取信息

如果是为了获取信息

下面为解决代码


StringBuffer content=new StringBuffer

try{
                  o = part.getContent();
            }catch(UnsupportedEncodingException e){
                 InputStream is = part.getInputStream();
                 content.append(inputStream2String(is));
                 continue;
            }



public static String inputStream2String(InputStream in)throws IOException   {
        StringBuffer out = new StringBuffer();
        byte[] b = new byte[4096];
        for(int n; (n=in.read(b))!=-1;){
              out.append(new String(b,0,n));
        }
        return out.toString();

}

可将附件内容转换为String

原创粉丝点击