JSP文件读取问题

yangnanayang 2012-08-20 10:01:43
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.io.*" %>
<html>
<head>
读取文件数据
</head>

<body>
<%
try{
String path=getServletContext().getRealPath("dt.txt");
FileReader input=new FileReader(path+File.separator+"dt.txt");
int in=input.read();
while(in!=-1){
out.print((char)in);
in=input.read();
if(in==13){
out.print("<br>");
input.skip(1);
in=input.read();
}
}
input.close();
}catch(FileNotFoundException fnfe){
out.print(fnfe);
}catch(IOException ioe){
out.println(ioe);
}
%>
</body>
</html>
读取文件数据 java.io.FileNotFoundException: C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\file\dt.txt (系统找不到指定的文件。)
请问JSP开发时文件应该要放在什么目录下才会被读取?
...全文
14 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

10,608

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 其他
社区管理员
  • 其他
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧