파일내용은 (탭구분자, ANSI)
apple 사과
banana 바나나
kiwi 키위
subak 수박
melon 멜론
orange 오렌지
이것을 해시맵으로 읽어들여 키와 밸류를 출력시킨다.
static void jwtest() {
try {
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("jwtest.txt"), "MS949"));
//BufferedReader br = new BufferedReader(new FileReader("jwtest.txt"));
String str ="";
Map<String, String> fruit = new HashMap<String, String>();
while ( (str = br.readLine()) != null ) {
String[] arr = str.split("\t");
fruit.put(arr[0], arr[1]);
}
Iterator kv = fruit.entrySet().iterator();
while(kv.hasNext()) {
Map.Entry entry = (Map.Entry) kv.next();
System.out.println(entry.getKey()+"__"+entry.getValue());
}
br.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
'업무 > Java' 카테고리의 다른 글
[javascript] 팝업창의 링크를 부모창에 호출시키기 (0) | 2012.09.24 |
---|---|
[java] 시스템정보 알아내기 (0) | 2012.06.22 |
[java] Spring 스케줄러, QuartzJobBean (0) | 2012.05.21 |
[java] euc-kr , utf-8 인코딩 변환 (0) | 2012.04.30 |
[java] hashtable 사용 (0) | 2012.02.08 |