Guest User

Untitled

a guest
May 27th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. package one;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.FileNotFoundException;
  5. import java.io.FileReader;
  6. import java.io.IOException;
  7. import java.util.HashMap;
  8. import java.util.Map;
  9.  
  10. /**
  11. * info.txtの中身
  12. * a,い
  13. * b,ろ
  14. * c,は
  15. *
  16. * 使い方
  17. * String result = StaticMemoryUtil.resolve("a");
  18. * System.out.println(result); // い
  19. *
  20. * @author honjo
  21. *
  22. */
  23. public final class StaticMemoryUtil {
  24.  
  25. private static final String PATH = "C:/develop/eclipse/pleiades-e3.5-java_20100226/workspace/javatest/info.txt";
  26.  
  27. private static Map<String, String> map;
  28.  
  29. static {
  30. init();
  31. }
  32.  
  33. private StaticMemoryUtil() {
  34.  
  35. }
  36.  
  37. public static void init() {
  38. Map<String, String> localMap = new HashMap<String, String>();
  39. BufferedReader br = null;
  40. try {
  41. br = new BufferedReader(new FileReader(PATH));
  42. String line = null;
  43. while ((line = br.readLine()) != null) {
  44. String[] lineSplit = line.split(",");
  45. localMap.put(lineSplit[0], lineSplit[1]);
  46. }
  47. map = localMap;
  48. } catch (FileNotFoundException e) {
  49. e.printStackTrace();
  50. } catch (IOException e) {
  51. e.printStackTrace();
  52. } finally {
  53. if (br != null) {
  54. try {
  55. br.close();
  56. } catch (IOException e) {
  57. e.printStackTrace();
  58. }
  59. }
  60. }
  61. }
  62.  
  63. public static String resolve(String token) {
  64. return map.get(token);
  65. }
  66. }
Add Comment
Please, Sign In to add comment