2010-12-28 6 views
0

나는 응용 프로그램을 만들어 웹 응용 프로그램에 새 폴더 (예 : appcustom)로 저장했습니다.
일부 텍스트 파일을 읽고 싶습니다.
경로를 하드 코딩하는 대신 전체적으로 읽는 방법은 무엇입니까?Red5에서 응용 프로그램 경로를 얻는 방법 (절대 및 상대)

FileReader fr = new FileReader("webapps/appcustom/<<textfilename>>"); // read a file 

가 어떻게 그것이 일반해야합니까 :

현재 나는 이런 식으로 뭔가를 사용하고? 내일은 응용 프로그램 폴더 이름을 "custApp"또는 다른 것으로 변경하려고 할 수 있습니다.

답변

0
Properties props = new Properties(); 
    // Looks for the file 'database.properties' in {TOMCAT_HOME}\webapps\{RED5_HOME}\WEB-INF\ 
    FileInputStream in = new FileInputStream(System.getProperty("red5.config_root") + "/database.properties"); 
    props.load(in); 

이 방법은 모든 파일을 읽는 데 매우 유용합니다.

Here is the link of full example

2

당신이 Red5의에서 사용할 수있는 몇 가지 시스템의 숙소 중 한 곳입니다, 나는이 블록을 사용하는 것이 확인 할 수 있습니다 수업 :


FileReader fr = new FileReader(String.format("%s/%s/%s", System.getProperty("red5.webapp.root"), appName, fileName)); 

응용 프로그램 이름 (예 : oflaDemo)과 파일 이름을 입력해야합니다.


FileReader fr = new FileReader(String.format("%s/%s/%s", System.getProperty("red5.webapp.root"), getScope().getName(), fileName)); 

당신은 전체 경로에 액세스 할 수 있습니다 서블릿에서 :


FileReader fr = new FileReader(String.format("%s/%s", getServletContext().getRealPath("/"), fileName)); 
을 당신이 "사용 가능한"응용 프로그램 이름에 액세스 할 수 ApplicationAdapter에서

관련 문제