
I was stuck with a java project where I have to read a file with two different concepts and store them differently in hashmap. My data file would be something like
Adults:
Name, xyz (Key, value)
ID, 123 (key, value)
Children:
Name, abc
ID, 321 and so on........
Here two concepts adults and children in file should be stored in two different maps. Any help will be appreciated. Thanks in advance.

Here is a simple example of storing the text file data into HashMap.
import java.io.*;
import java.util.*;
class OnlyExt implements FilenameFilter{
String ext;
public OnlyExt(String ext){
this.ext="." + ext;
}
public boolean accept(File dir,String name){
return name.endsWith(ext);
}
}
class MapExample{
public static void main(String[] args)throws Exception{
FilenameFilter ff = new OnlyExt("txt");
File folder = new File("c:/");
File[] files = folder.listFiles(ff);
Map<String,String> map=new LinkedHashMap<String,String>();
for(int i=0;i<files.length;i++){
FileReader fr = new FileReader(files[i].getPath());
BufferedReader reader = new BufferedReader(fr);
String st = "",str=" ";
while((st = reader.readLine()) != null) {
str+=st;
}
map.put(files[i].getName(),str);
}
Set set = map.entrySet();
Iterator i = set.iterator();
while(i.hasNext()){
Map.Entry me = (Map.Entry)i.next();
System.out.println(me.getKey() + " \t:\t " + me.getValue());
}
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.