以下所有方式均是获取 maven工程的 resources根目录下的jdbc.properties 的InputStream
-
InputStream is = 当前类名.class.getClassLoader().getResourceAsStream("jdbc.properties");
-
InputStream is = Class.class.getResourceAsStream("/jdbc.properties");
-
URL url = 当前类名.class.getClassLoader().getResource("jdbc.properties");
InputStream is = new FIleInputStream(new File(url.getFile())); -
(需要spring相关jar):Resource resource = new ClassPathResource("jdbc.properties");
InputStream is= resource.getInputStream()