快捷导航

系统找不到指定的文件

public Map getProperties() {
        Properties props = new Properties();
        Map 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;
    }
要是我这样用相对路径就抛异常说找不到文件,要是用上面的绝对路径就没错。相对路径是绝对没错的,这个类和文件都在同一个包下面

免责声明:本内容仅代表回答者见解不代表本站观点,请谨慎对待。

版权声明:作者保留权利,不代表本站立场。

回复

使用道具 举报

参与会员1

你试下把\换成/
回复

使用道具 举报

可能感兴趣的问答

发新帖
  • 微信访问
  • 手机APP