public Map<String, String> getProperties() { Properties props = new Properties(); Map<String, String> map = new HashMap<>(); try {// InputStream in = new FileInputStream("D:\\IntellijWorkspace\\designpattern\\src\\main\\java\\com\\umbrella\\factory\\simple\\type.properties"); InputStream in = new FileInputStream("type.properties"); props.load(in); Enumeration en = props.propertyNames(); while (en.hasMoreElements()) { String key = (String) en.nextElement(); String property = (String) props.get(key); map.put(key, property); } } catch (IOException e) { e.printStackTrace(); } return map; }要是我这样用相对路径就抛异常说找不到文件,要是用上面的绝对路径就没错。相对路径是绝对没错的,这个类和文件都在同一个包下面
添加回答
举报
0/150
提交
取消