JSP读写文件操作的例子源码下载

JSP读写文件操作的例子源码下载说明:

1.htm 负责收集用户的输入,把用户输入的文字提交给Filewriter.jsp

Filewriter.jsp负责把用户输入的文字写到file2.txt文件中保存
2.jsp负责读取file2.txt文件中的数据
好空间网络教程演示!
www.8isp.cn为您提供专业稳定的jsp空间!

jsp源码例子:

<%@ page language=”java” contentType=”text/html; charset=gb2312″%>
<%@ page import=”java.io.*”%>
<html>
<head>
<title>将内容写入到文件</title>
</head>
<body>
<center>
<%
String path=request.getRealPath(“/”);
File fp=new File(path,”file2.txt”);
FileWriter fwriter=new FileWriter(fp);
request.setCharacterEncoding(“GBK”);
String str_file=request.getParameter(“textarea”);
fwriter.write(str_file);
fwriter.close();
out.println(“已将内容成功写入到文件!”);
%>
</center>
</body>
</html>

jsp读写文件操作例子源码下载
<%@ page language=”java” contentType=”text/html;charset=gb2312″%>
<%@ page import=”java.io.*”%>
<html>
<head>
<title>使用FileInputStream类读取文件内容</title>
</head>
<body>
<%
byte buf[]=new byte[10000];
try{
String path=request.getRealPath(“/”);
File fp=new File(path,”file2.txt”);
FileInputStream fistream=new FileInputStream(fp);
int bytesum=fistream.read(buf,0,10000);
String str_file=new String(buf,0,bytesum);
out.println(str_file);
fistream.close();
}catch(IOException e) {
out.println(“文件读取错误!”);
}
%>
</body>
</html>

  本文链接地址: JSP读写文件操作的例子源码下载