• Post Reply Bookmark Topic Watch Topic
  • New Topic

fill a HashMap from a file  RSS feed

 
Urs Waefler
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are two files saved on my desktop.

1. datei_schluesselwort.txt
2. datei_antwort.txt

There is a HashMap: private HashMap<String, String> antwortMap;

I wrote this method:



It seems, it does not work.

I want to fill the HashMap antwortMap from the two files. First one has to read the content of the files. Then one has to put it into the HashMap antwortMap.
Who can help to analyze the source code. I do not understand it properly, maybe it is totally wrong.
 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Do not ever Ever EVER do this. You are probably getting an exception and you would never know it from this code. At the VERY least, invoke e.printStackTrace() so you can see an exception when it occurs.
 
Nicholas Jordan
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Subordinated to what Joe directs:

You can split a string on a wide range of printable characters. This is better than splitting across two files.



The file contains name value pairs:
bill administrator
charlie character
david delta

[ February 12, 2008: Message edited by: Nicholas Jordan ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!