package com.test.readtatle;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.Map;
public class ReadTatle {
public static void main(String[] args) throws IOException {
String entitiy = "GBK";
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>();
byte[] newbyte = null;
int begin = 0;
int end = 0;
for (int i = 0; i < b.length; i++) {
// Integer.toHexString()轉(zhuǎn)化十六進(jìn)制
//
if (Integer.toHexString(b[i]).equals("a") || i == b.length - 1) {
end = i;
//如果i等于byte[]數(shù)組長度減去1
if (i == b.length - 1) {
end++;
}
//創(chuàng)建一個新的byte數(shù)組并且它的長度為end - begin
newbyte = new byte[end - begin];
//然后給新的byte數(shù)組copy值,(數(shù)據(jù)源,數(shù)據(jù)開始的地方,copy到的地方,copy到的數(shù)組放的起始位置,復(fù)制的長度)
System.arraycopy(b, begin, newbyte, 0, end - begin);
begin = end + 1;
//把字節(jié)數(shù)組轉(zhuǎn)為字符串,第一個參數(shù)是字節(jié)數(shù)組,第二個參數(shù)是字符編碼
String s = new String(newbyte, entitiy);
System.out.println(s);
//創(chuàng)建一個索引尋找冒號
int eml = s.indexOf(":");
//如果還有冒號
if (eml != -1) {
//第一個int為開始的索引,對應(yīng)String數(shù)字中的開始位置,
//第二個是截止的索引位置,對應(yīng)String中的結(jié)束位置
String emlKey = s.substring(0, eml);
String emlVal = s.substring(eml + 1, s.length());
//把創(chuàng)建好的key跟val放到map.put里
map.put(emlKey, emlVal);
}
}
}
// Map.Entry是Map聲明的一個內(nèi)部泛型接口,entrySet()是它的方法,ntrySet()的返回值是Set集合,此集合的類型為Map.Entry
for (Map.Entry<String, String> entry : map.entrySet()) {
System.out.println("key=" + entry.getKey() + "value=" + entry.getValue());
}
}
}
?
?
這個代碼中,這一行是神馬意思
(Integer.toHexString(b[i]).equals("a") || i == b.length - 1)
.equals到底是什么意思?
慕碼人8056858
2018-12-07 10:36:23