我要读使用servlet.here文件是代码IAM using.but文件不读书用这个code.Always打印File contains null value-----------------
:文件阅读问题的servlet
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {
response.setContentType("text/html");
String filename = "D/root.properties";
ServletContext context = getServletContext();
InputStream inp = context.getResourceAsStream(filename);
if (inp != null) {
InputStreamReader isr = new InputStreamReader(inp);
BufferedReader reader = new BufferedReader(isr);
PrintWriter pw = response.getWriter();
String text = "";
while ((text = reader.readLine()) != null) {
}
} else {
System.out.println("File contains null value-----------------");
}
} catch(Exception e) {
System.out.println("Rxpn............................................."+e);
}
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request,response);
}
检查文件路径和文件内容 – 2011-12-28 09:45:11
文件内容和文件路径是否正确 – chinchu 2011-12-28 09:46:10
这是你正在使用的绝对路径吗?另外,它是'D:/ root.properties'(你似乎缺少斜线)? – 2011-12-28 09:46:38