<%@ page contentType="text/html;charset=gb2312"%> 
<%@ page import="java.io.*"%> 
<html> 
<head> 
<title>将写入文件的数据分行</title> 
</head> 
<body> 
<% 
String path=request.getRealPath("."); 
FileWriter fw=new FileWriter(path + "\\WriteData.txt"); 
BufferedWriter bw=new BufferedWriter(fw); 
bw.write("Hello!"); 
bw.write("Welcome to JSP!"); 
bw.newLine(); 	// 断行 
bw.write("Thanks!"); 
bw.newLine();	// 断行 
bw.write("email: mouse@cat.com"); 
bw.flush();		// 将数据更新至文件 
fw.close();		// 关闭文件流 
out.println("写入文件内容为：<br>"); 
FileReader fr=new FileReader(path + "\\WriteData.txt"); 
BufferedReader br=new BufferedReader(fr); 
String Line=br.readLine();	// 读取一行数据 
while(Line!=null){ 
out.println(Line + "<br>"); 
Line=br.readLine(); 
} 
fr.close(); 
%> 
</body> 
</html> 
