I'm just wondering if this logic is possible, what I want to do is to read text file line by line and store it to HashMap. I want to store the first 4 line into key of hashMap and when the lines read the checkpoint, the next line will be stored to value of HashMap.
File file1 = new File("C:\test\testfolder\test.txt");
HashMap<String,String> hashMap = new HashMap();
String check = "checkpointone";
try{
LineIterator it = FileUtils.lineIterator(file1,"UTF-8");
String line;
while(it.hasNext()){
line = it.nextLine();
hashMap.put(line , null);
if(line.contains(check)){
//do the logic here
}
}
}
catch(Exception ex){
ex.printStackTrace();
}
test.txt data :
test1
test2
test3
test4
checkpointone
get1
get2
get3
get4