流沙团
servlet读取Context 文件
2016-7-7 流沙团
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();
}

}
发表评论:
昵称

邮件地址 (选填)

个人主页 (选填)

内容