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
提交
取消