import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; public class propfile { static Map getKeyValue(String fileName) throws IOException { Map m = new HashMap(); try (FileReader f = new FileReader(fileName); BufferedReader br = new BufferedReader(f)) { while (br.ready()) { String s = br.readLine(); int o = s.indexOf(':'); if (o == -1) continue; m.put(o == 0 ? "" : s.substring(0, o).trim(), s.substring(o + 1).trim()); } } catch (FileNotFoundException e) { System.out.println("File not found: " + fileName); } return m; } public static void main(String [] args) throws IOException { Map m = getKeyValue(args[0]); for (Entry kv : m.entrySet()) { System.out.println(kv.getKey() + ":" + kv.getValue()); } } }