2012-09-27 4 views
0

특성 파일의 절대 경로는 어떻게 제공합니까?Java의 특성 파일 읽기

autoamtion_environment_properties = new Properties(); 
InputStream iStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(("C:\\automation_environment.properties")); 

이것은 null pointer exception입니다.

프로젝트 루트 폴더에이 파일이 있으면 작동하지만 외부에서 액세스해야합니다. 어떤 아이디어가 필요합니까?

감사합니다.

답변

3

파일이 작동하려면 CLASSPATH에 있어야합니다. 귀하의 IDE는 어려움을 극복하지만, 목발이 없을 때 무엇을하고 있는지 알아야합니다. CLASSPATH에 .properties 파일이있는 디렉토리를 포함 시키십시오.

1

, 당신은이 답변을 참조하시기 바랍니다,

InputStream iStream = new FileInputStream(new File("C:\\automation_environment.properties")); 

그렇지 않으면 FileInputStream의 클래스를 사용할 수 있습니다 https://stackoverflow.com/a/676273/176569

0
내가하려고 할

\ 대신 /을 다음과 같이 설정하십시오. InputStream iStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(("C:/automation_environment.properties"));