package com.gnudeveloper.sandbox; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class FileAccessServlet extends HttpServlet { private static final long serialVersionUID = 1L; String message = null; public void loadMessage() { try (BufferedReader br = new BufferedReader(new FileReader("I:\\www.gnudeveloper.com\\content\\msg.txt"))) { message = br.readLine(); System.out.println("message" + message); } catch (FileNotFoundException e) { System.out.println("file not found "); e.printStackTrace(); } catch (IOException e) { System.out.println("file not found io exception "); // TODO Auto-generated catch block e.printStackTrace(); } } public void init() { loadMessage(); System.out.println("this is init"); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { response.getOutputStream().print("message=" + message); } }