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()轉化十六進制
//
if (Integer.toHexString(b[i]).equals("a") || i == b.length - 1) {
end = i;
//如果i等于byte[]數組長度減去1
if (i == b.length - 1) {
end++;
}
//創建一個新的byte數組并且它的長度為end - begin
newbyte = new byte[end - begin];
//然后給新的byte數組copy值,(數據源,數據開始的地方,copy到的地方,copy到的數組放的起始位置,復制的長度)
System.arraycopy(b, begin, newbyte, 0, end - begin);
begin = end + 1;
//把字節數組轉為字符串,第一個參數是字節數組,第二個參數是字符編碼
String s = new String(newbyte, entitiy);
System.out.println(s);
//創建一個索引尋找冒號
int eml = s.indexOf(":");
//如果還有冒號
if (eml != -1) {
//第一個int為開始的索引,對應String數字中的開始位置,
//第二個是截止的索引位置,對應String中的結束位置
String emlKey = s.substring(0, eml);
String emlVal = s.substring(eml + 1, s.length());
//把創建好的key跟val放到map.put里
map.put(emlKey, emlVal);
}
}
}
// Map.Entry是Map聲明的一個內部泛型接口,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