카테고리 없음
[Java] CLASSPATH , 경로 탐색
junjunwon
2021. 2. 25. 17:54
절대경로
this.getClass().getResource("").getPath(); // 현재 자신의 절대 경로
this.getClass().getResource("/").getPath(); // classes 폴더의 최상위 경로
this.getClass().getResource("/com/test/config/config.properties").getPath(); // classes 폴더에서부터 시작하여 해당파일까지의 절대 경로
현재 클래스가 상속되는(부모) 클래스라면 클래스명.class.getResource 로 해야 한다.
getClass()는 실행되는 현재 자신(자식클래스가 될 수 있음)을 가리키기 때문이다.
WEB의 절대경로와 다르다..
new File("").getAbsolutePath() : 절대경로
new File("").getCanonicalPath() : 상대경로
출처 :
java 경로 표시
Java 절대경로 this.getClass().getResource("").getPath(); // 현재 자신의 절대 경로 this.getClass().getResource("/").getPath(); // classes 폴더의 최상위 경로 this.getClass().getResource("/com/test/con..
blog.daum.net