首先从文件读出一行,然后分解成2个token,在写入hashtable
到文件结束,这样就得到一个id索引的hashtable可以方便使用了
readline-->stringtokenizer-->hashtable

解决方案 »

  1.   

    顺便给出例子
    package test;import java.io.*;
    import java.util.*;public class testfile {
      public static void main(String[] args) {
        String filename = "testfile.txt";
        Hashtable h = new Hashtable();
        try{
          BufferedReader in = new BufferedReader(new FileReader(filename));
          String str = in.readLine();
          while (str != null)
          {
            StringTokenizer st = new StringTokenizer(str, "=");
            while (st.hasMoreTokens())
            {
              String id = st.nextToken();
              String name = st.nextToken();
              h.put(id, name);
            }
            str = in.readLine();
          }
          in.close();
        }
        catch(IOException e)
        {
          e.printStackTrace();
        }
        catch(Exception ee)
        {
          ee.printStackTrace();
        }
        //test if get right
        String result = (String)h.get("1111");
        if (result != null) {
        System.out.println("1111 = " + result);
        }
      }
    }
      

  2.   

    java.util.Property类 很方便的
      

  3.   

    阿 笔误  java.util.Properties
      

  4.   

    Properties property = new Properties();
    property.load(new FileInputStream(new File(filename)));
    property.getProperties("1111"); 呵呵 是不是很方便
      

  5.   

    java.util.ResourceBundle最直接了,用它...具体的看看国际化的东东...
      

  6.   

    很同意copyright(笨蛋白痴神经质) 
    不过我觉得不用建一个哈西表,就每次读入一行判断是否需要的id。是取出"="后面的,不是继续读。
      

  7.   

    直接readLine,然后使用String的split方法就可以获得了