특성 파일을로드하려고합니다. 적절한 파일은 응용 프로그램의 클래스 경로에 있습니다.Java에서 특성 파일을로드 할 수 없습니다.
Properties p = new Properties();
p.load(new FileInputStream("classpath:mail.properties"));
System.out.println(p.get("hi"));
는 지금은 x.properties라는 다른 파일 내가 x.properties 같은 폴더에 내 mail.properties을 배치이
<property name="x">
<util:properties location="classpath:x.properties" />
</property>
같은 XML 파일에 언급되어 있기 때문에, 클래스 경로를 말하지만, 내 Java 프로그램에서 찾을 수 없습니까? 내가 누락 된 어떤 아이디어?
클래스의 getClass()입니다. 예를 들어 TestProgram에서 main 메소드를 실행하고 있다면 TestProgram.class.getClass()가되어야합니까? – user2434
그러면'TestProgram.class.getResourceAsStream'을 사용할 수 있습니다. – aioobe
음 ... InputStream이 null이됩니다. – user2434