关于流的问题。高手帮我看看。

mx1029 2004-03-03 04:12:23
程序要实现的目的是,通过一个按钮的点击把textarea里的内容保存为文本文件。
我写的程序保存出来的文本是空的。
代码如下:

<%@page contentType="text/html;charset=gb2312"%>
<%@page import="java.io.*"%>
<jsp:useBean id="str" scope="page" class="getStr.getStr"/>
<%
String Title = request.getParameter("Title");//接收传过来的文件名
if(Title==null){Title = "";}
else{Title=str.getStr(Title);}//转换乱码
String contents = request.getParameter("contents");//接收传过来的文件内容
contents=str.getStr(contents);

String strChina = new String(Title.getBytes("gb2312"),"iso8859-1");
String fileName = strChina+".txt";
response.setContentType("APPLICATION/OCTET-STREAM");
response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName+ "\"");

try{
InputStream fileInput = new StringBufferInputStream(contents);
int data = fileInput.read();
while(data != -1){
out.write(data);
}
fileInput.close();
out.close();
}catch(IOException ioe){
out.print("I/O error:"+ioe);
}
%>
...全文
32 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复

81,091

社区成员

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

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