欢迎来到HELLO素材网! 南京网站制作选择顺炫科技
丰富的DIV CSS模版、JS,jQuery特效免费提供下载
当前位置:主页 > 建站教程 > 网站制作教程 >

在JSP中写text文件

发表于2019-04-24 01:02| 次阅读| 来源网络整理| 作者session

摘要:在JSP中写text文件
在JSP中写text文件

    利用PrintWriter对象即可在JSP写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 %>">