UNIX下绝对路径问题

3332221119 2005-01-12 09:49:38
我需要访问/home/user下的一个文件,请教如何打开这个文件?
...全文
216 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
bboonnee 2005-01-12
  • 打赏
  • 举报
回复
/home/user
必须再服务器可以访问的目录内才可以访问到
这也是安去性的要求
3332221119 2005-01-12
  • 打赏
  • 举报
回复
文件目录不在web目录下,上述方法行不通,谢谢
peterpansh 2005-01-12
  • 打赏
  • 举报
回复
<%@ page contentType="text/html; charset=GB2312"
import="java.io.*" %>
<html>
<head>
<title>Counter</title>
</head>
<body>
<center><b>
<font size=4 color=red>客访计数器</font><br>
<hr><br>
您是第
<%
String pth = request.getRealPath("./");
FileReader fr = new FileReader(pth + "\\cont1.txt");
BufferedReader br = new BufferedReader(fr);
String cnt = br.readLine();
br.close();
fr.close();
out.print(cnt);
FileWriter fw = new FileWriter(pth + "\\cont1.txt");
int cntint = Integer.parseInt(cnt) + 1;
fw.write(String.valueOf(cntint));
fw.close();
%>
位访问者
</b></center>
</body>
</html>
peterpansh 2005-01-12
  • 打赏
  • 举报
回复
<%@ page contentType="text/html; charset=GB2312"%>
<%@ page import="java.io.*" %>
<html>
<head>
<title>写入文件</title>
</head>
<body>
<center><b>
<font size=4 color=red>回执</font><br>
<hr><br>
您输入的内容已写入文件wtfl.txt,请核实。
</b></center>
<%
String path = request.getRealPath("./");
FileWriter fw = new FileWriter(path + "\\wtfl.txt");
String str=request.getParameter("txarea");
fw.write(str);
fw.close();
%>
</body>
</html>
peterpansh 2005-01-12
  • 打赏
  • 举报
回复
<%@ page contentType="text/html; charset=GB2312"
import="java.io.*" %>
<html>
<head>
<title>读出文件</title>
</head>
<body>
<center><b>
<font size=4 color=red>读出文件</font><br>
</b></center>
<hr><br>
<%
String pth = request.getRealPath("./");
FileReader flrd = new FileReader(pth + "\\rdfl.txt");
int aa = flrd.read();
while(aa != -1)
{
out.print((char)aa);
aa = flrd.read();
if(aa == 13)
{
out.print("<br>");
flrd.skip(1);
aa = flrd.read();
}
}
flrd.close();
%>
</body>
</html>

jFresH_MaN 2005-01-12
  • 打赏
  • 举报
回复
你是说访问你的服务器端的文件吧
直接用绝对路径不行吗
3332221119 2005-01-12
  • 打赏
  • 举报
回复
up

81,122

社区成员

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

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