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?
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.
您可以使用集合(即List(java.util.List)。也可以将对象的集合存储在文件中(我认为使用serialize和de-serialize可以提高读取和写入数据的速度)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.