Properties is backed by a Hashtable so the key must be unique.
So if you want to stick to multiple instances of the same key you can implement the parsing yourself (if you don't depend too much on the extras managed by Properties):
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
public class FileInput {
Properties porp;
public static Map<String, List<String>> loadProperties(String file) throws IOException
{
HashMap<String, List<String>> multiMap = new HashMap<>();
try (BufferedReader br = new BufferedReader(new FileReader(file))) {
String line = null;
while ((line = br.readLine()) != null) {
if (line.startsWith("#"))
continue; // skip comment lines
String[] parts = line.split("=");
multiMap.computeIfAbsent(parts[0].trim(), k -> new ArrayList<String>()).add(parts[1].trim());
}
}
return multiMap;
}
public static void main(String[] args) throws IOException {
Map<String,List<String>> result=loadProperties("myproperties.properties");
}
}
UPDATED: improved exception handling (valid remark @rzwitsersloot). I prefer to throw the exception so the caller can decide what to do if the properties file is missing.