描述:将若干文本内容写入一个文件,然后读取这个文件,并将文件的内容显示给用户。
example5_6.jsp
<%@ page contentType="text/html; charset=GB2312" %>
<%@ page import="java.io.*" %>
<HTML><BODY bgcolor="green">
<%
File dir = new File("E:/", "JSP");
dir.mkdir();
File f = new File(dir, "file01.dat");
try {
BufferedOutputStream bufout = new BufferedOutputStream(new FileOutputStream(f));
byte[] b = "Hello!<BR>Nice to meet you!".getBytes();
bufout.write(b);
bufout.flush();
bufout.close();
BufferedInputStream bufin = new BufferedInputStream(new FileInputStream(f));
byte[] c = new byte[100];
int n = 0;
while((n=bufin.read(c)) != -1) {
String temp = new String(c, 0, n);
out.print(temp);
}
bufin.close();
} catch (IOException ex) {
out.print(ex);
}
%>
</BODY></HTML>