java读取WEB-INF目录下文件

 public void doGet(HttpServletRequest request, HttpServletResponse response)
   throws ServletException, IOException {
  String output = "";
  String fileName = request.getSession().getServletContext().getRealPath(
    "/")
    + "WEB-INF/conf/ff.txt";
  fileName = fileName.replace("\\", "/");
  System.out.println(fileName);
  File file = new File(fileName);

  try {
   BufferedReader input = new BufferedReader(new FileReader(file));
   StringBuffer buffer = new StringBuffer();
   String text;

   while ((text = input.readLine()) != null)
    buffer.append(text + "\n");

   output = buffer.toString();
  } catch (IOException ioException) {
   System.err.println("File Error!");
  }
  request.setAttribute("output", output);
  request.getRequestDispatcher("/WEB-INF/jsp/FileDemo.jsp").forward(
    request, response);

 }

你可能感兴趣的:(java,Web,jsp)