Note that there are some explanatory texts on larger screens.

plurals
  1. POJava: Reading a file, first line missing
    text
    copied!<p>I have an <code>HashMap&lt;String, String&gt;</code> which keeps the filename and the display name of an image. I read a file line by line and add the key and values to HashMap.</p> <pre><code>BufferedReader reader; String line; String[] lineSplit; HashMap&lt;String, String&gt; imenaZnaki = new HashMap&lt;String, String&gt;(); try { reader = new BufferedReader(new InputStreamReader(am.open("znaki_imena.txt"), "UTF-8")); line = reader.readLine(); while (line != null) { lineSplit = line.split("-&gt;"); imenaZnaki.put(lineSplit[0], lineSplit[1]); line = reader.readLine(); } reader.close(); } catch (IOException e) { e.printStackTrace(); } </code></pre> <p>Everything works as expected, except for the first added entry, the <code>.get(key)</code> returns null and <code>.containsKey(key)</code> returns false. All the other key/values work and are properly stored in the HashMap.</p> <p><strong>EDIT:</strong></p> <p>This makes no sense at all... After I added the content to HashMap I runned the code that MagicMan provided to check if all the entrys are inside the HashMap</p> <pre><code>for(String key: imenaZnaki.keySet()) { System.out.println("KEY: " + key + " VALUE: " + imenaZnaki.get(key)); } </code></pre> <p>And if I would <kbd>CTRL + F</kbd> for "nevar_andrej" it would show me 4 outputs, which is correct. But if I searched for " nevar_andrej" (with a whitespace) it would only show 3 of them, which is wrong, because the first one would be missing. So my guess is, that there is something in the first line of the file that causes confusion. So I added a dummy/fake first line (bla_bla->Bla bla) and it works, but it is a nasty workaround.</p> <p>This is my full text file that is encoded with UTF-8 <a href="http://pastebin.com/6A4r4jm6" rel="nofollow">http://pastebin.com/6A4r4jm6</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload