public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String ip = request.getRemoteAddr(); System.out.println(ip); //读取 3.txt String path3 = getServletContext().getRealPath("/WEB-INF/5.txt"); System.out.println(path3); readContent(path3); } public static void readContent(String path){ try { InputStream in = new FileInputStream(path); byte[] buf = new byte[1024]; int len = 0 ; while((len = in.read(buf))!= -1){ System.out.println(new String(buf,0,len)); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
0则评论给“servlet读取Context 文件”