Reading Text File into Java HashMap
We will look into the Method that allows us to read the HashMap Text from the file or how we can De-serialised the File
De-Serialization: Here we are reproducing the HashMap object and it’s content from a serialized file.
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.
Firstly the method/Function HashMapFromTextFile will have the Method bufferedReader which read the Line of the text File and insert into the map and then return the Map
bf = new BufferedWriter( new FileWriter(file_name) );
- Firstly we call the BufferedReader to read each line.
- At each Line, We have the Key-Value Pair. So, Now split it by “:” and same time put the key and Value to the map
- and return the Map