服务热线
13902905075
TOP
在JSP中写text文件

使用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"应该已经写入。