파일 설명자를 사용하여 doGet 메서드에서 Tomcat 컨테이너의 파일을 읽으려고합니다. 실행될 때 프로그램은 tomcat bin 폴더 아래에서 "sample.txt"를 찾습니다. 내 리소스 파일을 Tomcat bin에 포함시키고 싶지 않다. 리소스 디렉토리를 유연하게 정의 할 수있는 더 나은 방법으로 파일을 읽는 방법은 무엇입니까? 또한 Tomcat에서 도우미 클래스로 배포 된 POJO에서 파일을 읽으려고합니다. 다른 디렉토리에서 파일을 찾을 수 있도록 tomcat의 classpath도 구성 할 수 있습니까? 모든 포인터가 도움이 될 것입니다.Tomcat의/bin 폴더에 넣지 않고 webapp에서 파일을 읽는 방법
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
out.print("Sample Text");
RSAPublicCertificate rsa = new RSAPublicCertificate();
out.print(rsa.getCertificate());
File file = new File("sample.txt");
out.print(file.getAbsolutePath());
FileInputStream in = new FileInputStream(file);
}
D:\apache-tomcat-6.0.20\bin\sample.txt