<%@ page import=javaio* %>
<html>
<head>
<title>Lion互动网络==》JSP中读文件和写文件的例子</title>
</head>
<body>
<%
//写文件
String str = WWWLIONSKYNET;
String filename = requestgetRealPath(lionskytxt);
javaioFile f = new javaioFile(filename);
if(!fexists())//如果文件不存则建立
{
fcreateNewFile();
}
try
{
PrintWriter pw = new PrintWriter(new FileOutputStream(filename));
pwprintln(str);//写内容
pwclose();
}
catch(IOException e)
{
outprintln(egetMessage());
}
//读文件
javaioFileReader fr = new javaioFileReader(f);
char[] buffer = new char[];
int length; //读出的字符数(一个中文为一个字符)
//读文件内容
outwrite(filename+<br>);
while((length=frread(buffer))!=)
{
//输出
outwrite(bufferlength);
}
frclose();
%>
</body>
</html>