jsp如何写文件
发布网友
发布时间:2022-04-09 13:58
我来回答
共4个回答
热心网友
时间:2022-04-09 15:27
jsp内容写入txt文件的方法:
jsp页面点击down:
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<HTML>
<HEAD>
</HEAD>
<BODY>
<a href = "download1.jsp?filepath=d:\\&filename=1a.txt" >downloadtest1</a>
</BODY>
</HTML>
保存txt文件代码:
<%
String filename = request.getParameter("filename");//"1a.txt";
String filepath = request.getParameter("filepath");//"d:\\";
int i = 0;
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition","attachment;filename = "+filename);
java.io.FileInputStream fileInputStream = new java.io.FileInputStream(filepath+filename);
while((i= fileInputStream.read()) != -1){
out.write(i);
}
%>
热心网友
时间:2022-04-09 16:45
使用PrintWriter对象,如:
<%@ page import="java.io.*" %>
<%
String str = "print me";
String nameOfTextFile = "/usr/anil/imp.txt";
try {
PrintWriter pw = new PrintWriter(new FileOutputStream(nameOfTextFile));
pw.println(str);
pw.close();
} catch(IOException e) {
out.println(e.getMessage());
}
%>
热心网友
时间:2022-04-09 18:20
不是修改 是文件的追加
热心网友
时间:2022-04-09 20:11
是说的修改文件内容?