Java TreeMap<String, String> returns null even if the key exists
<p>I have a class which extends TreeMap with one external method.
The external method "open" suppose to read lines from a given file in the following format "word:meaning" and add it to the TreeMap - put("word", "meaning").</p>

<p>So I read the file with RandomAccessFile and put the keys-values in the TreeMap and when I print the TreeMap I can see the proper keys and values, for example:</p>

<pre><code>{AAAA=BBBB, CAB=yahoo!}
</code></pre>

<p>But for some reason when I do get("AAAA") I get null.</p>

<p>Any reason why it's happening and how to solve it?</p>

<p>Here is the code</p>

<pre><code>public class InMemoryDictionary extends TreeMap&lt;String, String&gt; implements
    PersistentDictionary {
private static final long serialVersionUID = 1L; // (because we're extending
                                                    // a serializable class)
private File dictFile;

public InMemoryDictionary(File dictFile) {
    super();
    this.dictFile = dictFile;
}

@Override
public void open() throws IOException {     
    clear();
    RandomAccessFile file = new RandomAccessFile(dictFile, "rw");
    file.seek(0);
    String line;
    while (null != (line = file.readLine())) {
        int firstColon = line.indexOf(":");
        put(line.substring(0, firstColon - 1),
                line.substring(firstColon + 1, line.length() - 1));
    }       
    file.close();
}

@Override
public void close() throws IOException {    
    dictFile.delete();
    RandomAccessFile file = new RandomAccessFile(dictFile, "rw");       
    file.seek(0);
    for (Map.Entry&lt;String, String&gt; entry : entrySet()) {            
        file.writeChars(entry.getKey() + ":" + entry.getValue() + "\n");
    }
    file.close();
}
</code></pre>

<p>}</p>
