views:

24

answers:

0

Hi,

I have a custom java library which getResource() from an UTF-8 encoded text file in the package.

keyWordPairs = new Hashtable<String, Vector<String>>();
  try {
   File pinYinDatabase = new File(this.getClass().getClassLoader().getResource("myCustomLibrary/NewPinYin.utf").getFile());
   BufferedReader br = new BufferedReader(new FileReader(pinYinDatabase));
   String line = br.readLine();
   while(line != null)
   {
    int posOfTab = line.indexOf(9);    // Get the position of a tab which separate code and word
    String key = line.substring(0, posOfTab);
    Vector<String> l = keyWordPairs.get(key);
    if (l == null) {
     keyWordPairs.put(key, l = new Vector<String>() );
    }
    l.add(line.substring(posOfTab+1, line.length()));
    System.out.println("Loaded: " + line.substring(0, posOfTab)+ "+" + line.substring(posOfTab+1, line.length()));
    line = br.readLine();
   }
   br.close();
  } catch (FileNotFoundException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } 

It works perfectly when I reference to this library in other Java projects.
But when I reference it from my Android project, I get nothing in the my HashTable.
Does anyone else has the same experience?

In addition, I have found the above situation in Anroid 1.5, 1.6 and 2.2.

Jeanno