views:

17

answers:

1

I have 1 text file which contains numbers from 1 to 11644. Beside the numbers are the names of the xml files that i have in another folder. I have a total of 8466 xml files. I need to match the filename of all the xml files with the id in the text file and extract the value of the id out. All of the id are in random position. An example would be my first xml file id is 7025, which means it's id is 7025. I'm new to java so i really hope someone would enlighten me thanks.

+1  A: 

The data structure for this is a map.

Read in the input file, and add each line to a java.util.HashMap<String, Integer>. The key should be the filename. The value should be the id. Thus, for each line, myMap.put(filename, id). Now, when you want to check the ID of a file, do myMap.get(filename). It will return the Integer ID of the file.

Borealid
Hey Borealid, may i know how to set both paths for the folder containing all the xml filenames and the text file with my id and filename?
Jason
Look at the java.io.File class. If you do File.new(path), the path may be absolute or relative to the working directory from which your Java code is running.What you store in the map is up to you - just be consistent. I suggest using canonical paths.
Borealid