这样从文件系统读取一个文件然后显示有问题吗?可是显示不出来

hehefaint 2001-12-28 08:21:06
<%@page import="java.io.*"%>
<%
try
{
String FileBase = "/home/htdoc/test/";
response.setContentType("image/gif");
File fp = new File(FileBase+"test.gif");
FileInputStream str = new FileInputStream(fp);
ServletOutputStream op = response.getOutputStream();

BufferedInputStream bis = null;
BufferedOutputStream bos = null;

bis = new BufferedInputStream(str);
bos = new BufferedOutputStream(op);

byte[] buff = new byte[5*1024*1024];
int bytesRead;

// Simple read/write loop.
while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
// out.println(bytesRead);
bos.write(buff, 0, bytesRead);
}
}
catch (FileNotFoundException e)
{
out.println(e.toString());
}
%>
...全文
54 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
hehefaint 2001-12-28
  • 打赏
  • 举报
回复
已经是全路径了阿.不然会FileNotFoundException的
ycats 2001-12-28
  • 打赏
  • 举报
回复
必须用全路径!--〉〉〉〉FileBase = "/home/htdoc/test/";

81,115

社区成员

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

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