Okay, Im working on a project that requires me to save a large volume of files. in the format .dat with information that the variable stores stored inside the file. Is there a way in Java 1.7 to create a variable with the name that it reads from file? If not what would be the best way to create an ever growing number of variables? Im at a bit of a loss, I don't know of a way to do what i need... Dpes anyone have any advice?
2 Answers
You can use any Map implementation like LinkedHashMap, HashMap or Hashtable. They all store objects classified by keys which have their corresponding values.
You would declare this object as:
Map myMap = new Hashtable<String, File>();
Do whatever implementation for file input, you can then use the put() method like:
myMap.put("fileName", fileInstance);
You can remove a key, check for a key existance, check for a value existance, iterate over the keys and over values.
ListorMap.