이런 일이 발생하는 이유가 궁금합니다. 동일한 코드이지만 다른 결과입니다.서블릿에서 속성 파일의 절대 경로를 가져올 수 없습니다.
File file = new File("src/config/ora2.config.properties");
System.out.println(file.getAbsolutePath());
정상적인 Java 클래스에서는 올바른 경로가되지만 서블릿에있을 때 eclipse의 설치 경로를 반환합니다.
Properties props = new Properties();
InputStream in = getServletContext().getResourceAsStream("WEB-INF/ora2.config.properties");
if(in != null) {
try {
props.load(in);
props.setProperty("username", "temtem");
FileOutputStream out = new FileOutputStream(in.toString());
props.store(out, null);
out.close();
} finally {
in.close();
}
코드 위의 편집을 할 사전
에서
덕분에 자바 프로세스의 현재 작업 디렉토리, 어떤이 상대적으로 :(
이 질문은 이해가되지 않습니다. Eclipse에서이 클래스를 실행 중임을 보여줍니다. –
예. 이클립스에서 이걸 달리는거야. 그것은 영향을 줍니까? 서블릿에서 올바른 절대 경로를 실행하려면 어떻게해야합니까? – user3264438