Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package one;
- import java.io.BufferedReader;
- import java.io.FileNotFoundException;
- import java.io.FileReader;
- import java.io.IOException;
- import java.util.HashMap;
- import java.util.Map;
- /**
- * info.txtの中身
- * a,い
- * b,ろ
- * c,は
- *
- * 使い方
- * String result = StaticMemoryUtil.resolve("a");
- * System.out.println(result); // い
- *
- * @author honjo
- *
- */
- public final class StaticMemoryUtil {
- private static final String PATH = "C:/develop/eclipse/pleiades-e3.5-java_20100226/workspace/javatest/info.txt";
- private static Map<String, String> map;
- static {
- init();
- }
- private StaticMemoryUtil() {
- }
- public static void init() {
- Map<String, String> localMap = new HashMap<String, String>();
- BufferedReader br = null;
- try {
- br = new BufferedReader(new FileReader(PATH));
- String line = null;
- while ((line = br.readLine()) != null) {
- String[] lineSplit = line.split(",");
- localMap.put(lineSplit[0], lineSplit[1]);
- }
- map = localMap;
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- } finally {
- if (br != null) {
- try {
- br.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- }
- public static String resolve(String token) {
- return map.get(token);
- }
- }
Add Comment
Please, Sign In to add comment