<%@ page contentType="text/html;charset=gb2312"%> 
<%@ page import="java.io.*"%> 
<html> 
<head> 
<title>将写入文件的数据分行</title> 
</head> 
<body> 
<% 
String path=request.getRealPath("."); 
// 定义一个类RandomAccessFile的对象，并实例化 
RandomAccessFile rf=new RandomAccessFile(path + "\\WriteData.txt","rw"); 
// 将指针移动到文件末尾
rf.seek(rf.length()); 
rf.writeBytes("\nAppend a line to the file!"); 
rf.close();	// 关闭文件流 
out.println("写入文件内容为：<br>"); 
FileReader fr=new FileReader(path + "\\WriteData.txt"); 
// 读取文件的BufferedRead对象
BufferedReader br=new BufferedReader(fr); 
String Line=br.readLine(); 
while(Line!=null){ 
out.println(Line + "<br>"); 
Line=br.readLine(); 
} 
fr.close();//关闭文件 
%> 
</body> 
</html>
