首页 新闻 会员 周边

插入utf-8为何还是乱码?

0
[已关闭问题] 关闭于 2016-04-15 15:43
package com.test.loghost;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.LinkedHashMap;
import java.util.Map;

public class TestOne {

    public static void main(String[] args) throws IOException {
        BufferedInputStream bis=new BufferedInputStream(new FileInputStream("D:"+File.separator+"1.eml"));
        
        byte[] b=new byte[bis.available()];
        bis.read(b);
        bis.close();
        Map<String, String> map=new LinkedHashMap<String,String>();
        int begin=0;//接收换行开始
        int end=0;
        byte[] newbyte=null;//创建一个空byte[]接收换行前的字符串
        for(int i=0;i<b.length;i++){
            if(Integer.toHexString(b[i]).equals("\r\n") || i==b.length-1){//转16进制并且获取换行符
                end=i;                //读取到一个有换行的地方
                if(i==b.length-1){    //i=数组长度-1
                    end++;            //循环累加end
                }
                newbyte=new byte[end-begin];    //剩下的数组长度
//                public static void arraycopy(Object src, int srcPos, Object dest, int destPos, int length)
//                src -- 这是源数组.
//                srcPos -- 这是源数组中的起始位置。
//                dest -- 这是目标数组。
//                destPos -- 这是目标数据中的起始位置。
//                length -- 这是一个要复制的数组元素的数目。
                System.arraycopy(b, begin, newbyte, 0, end-begin);
                begin=end+1;
                //中文乱码
                String str=new String(newbyte,"utf-8");
                System.out.println(str);
                //索引,寻找:
                int tem=str.indexOf(":");
                if(tem!=-1){
                    String temkey=str.substring(0, tem);
                    String temvalue=str.substring(tem+1,str.length());
                    map.put(temkey, temvalue);
                }
            }
        }
        
        for(Map.Entry<String, String> entry:map.entrySet()){
            System.out.println("Key="+entry.getKey()+",Value="+entry.getValue());
        }
    }
}

XX-ClientMac: 12121212
XX-ServerMac: 321212q122
XX-ClientPort: 312
XX-ServerPort: 11
XX-ClientIp: 21244412
XX-ServerIp: 32322323
XX-Protocol: asd
XX-Time: 1saxaaa
XX-DeviceId: 1
XX-ClueId: 0
XX-ClueTypeId: 111
XX-TargetId: 0
XX-Associate: 2
XX-Request: NO
XX-PairId: 5
XX-Method: 2
XX-Url: http://g1a4.mail.42c.com/coxcmail/fcg/lzmsapp
XX-Param: funcid=readlett&sid=EAgdjjnaaxxlwujtXRCnnqKPMHWmrezmn&mid=1tbidRsnwkR3N5o9PQAAsV%250A117%2xzzx88632%250A1&fid=1&ord=0&desc=1&start=0&tempname=onepageread.htm&796
XX-Host: g1a4.mail.126.com
XX-Referer: http://mimg.1sxa.com/dmszx/html/blankcge.htm
XX-ContentType: text/html; charset=gb2312
XX-ResponseCode: tt
XX-Status: ssa
XX-SessionId: aaaaaaaaaaa
XX-Useful: YsaES
XX-Priotity: EXACT
XX-SiteName: xa
XX-Domain: vdax
XX-User: 12z
XX-Pass:
XX-MsgType: MAIL_asdREAD_SUBJECT
XX-ProState: REsSULT
XX-MailId: 1
XX-Composed: yesw1
XX-MailState: 6a

from: wuyitseng@seed.net.tw
to: yibin626@126.com
date:
subject: 读取: ?清???2006年9月?排行程
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="my-my-my-boundary-my-my-my"

问题补充:

现在输出的中文变成了这玩意

 ��ȡ: ?��???2006��9��?���г� 

师太来老道这坐坐的主页 师太来老道这坐坐 | 初学一级 | 园豆:34
提问于:2016-04-15 15:15
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册