略过文件中的字符不读取
<%@ page contentType=\"text/html;charset=gb2312\"%>
<%@ page import=\"java.io.*\"%>
<html>
<head>
<title>略过字节不读取</title>
</head>
<body>
<%
String path=request.getRealPath(\".\");
FileReader fr=new FileReader(path + \"\\\\ReadData.txt\");
fr.skip(2);//跳过2个字节
int c=fr.read();//读取一个字节
while(c!=-1){
out.print((char)c);
c=fr.read();
}
fr.close();
%>
</body>
</html>
将数据写入文件
<%@ 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\");//建立FileWriter对象,并实例化fw
//将字符串写入文件
fw.write(\"大家好!\");
fw.write(\"本书是《JSP编程技巧》\");
fw.write(\"请多多指教!\"); [Page]
fw.write(\"email:stride@sina.com\");
fw.close();
FileReader fr=new FileReader(path + \"\\\\WriteData.txt\");
BufferedReader br=new BufferedReader(fr);//建立BufferedReader对象,并实例化为br
String Line=br.readLine();
//读取一行数据
out.println(Line + \"<br>\");
br.close();//关闭BufferedReader对象
fr.close();
%>
</body>
</html>
将写入文件的数据分行
<%@ 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(\"大家好!\");
bw.write(\"本书是《JSP编程技巧》。\");
bw.newLine();//断行
bw.write(\"请多多指教!\");
bw.newLine();//断行
bw.write(\"email: stride@sina.com\");
bw.flush();//将数据更新至文件
fw.close();//关闭文件流
out.println(\"写入文件内容为:<br>\");
FileReader fr=new FileReader(path + \"\\\\WriteData.txt\");
BufferedReader br=new BufferedReader(