| 网站首页 | 新闻快报 | 软件教程 | 硬件教程 | 设计学院 | Q Q 专区 | 编程开发 | 网络安全 | 
您现在的位置: 浩扬网络 >> 编程开发 >> WEB编程 >> JSP编程 >> 教程正文
在JSP中写text文件
作者:不详 文章来源:安全中国 点击数: 更新时间:2006-8-5 0:08:54

作者: Blueski

使用PrintWriter对象即可写Text文件。

请参考以下示例:

<%@ page import="java.io.*" %>
<%
String str = "print me";
//always give the path from root. This way it almost always works.
String nameOfTextFile = "/usr/anil/imp.txt";
try {
PrintWriter pw = new PrintWriter(new FileOutputStream(nameOfTextFile));
pw.println(str);
//clean up
pw.close();
} catch(IOException e) {
out.println(e.getMessage());
}
%>

现在,打开imp.txt加以查看,字符串"print me"应该已经写入。

还有另一种方法,使用IN16标记库的file tag,可参考http://sourceforge.net/project/?group_id=1282.
其示例的语法为:
<ext:file action="write|append|create|copy|move|delete|rename|read" from="<%= myfilename %>"> 

【教程录入:残梦    责任编辑:残梦 】
发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
  • 上一篇教程:

  • 下一篇教程: 没有了
  • 网友评论:(评论内容只代表网友观点,与浩扬网络立场无关!)
    热门文章

    赞助商


    | 设为首页 | 加入收藏 | 联系站长 | 友情链接 | 版权申明 | 网站公告 |