<%--List8_5_1.jsp--%>
<%@ page import="java.io.FileReader,
                 java.io.BufferedReader,
                 java.io.FileWriter"%>
<%@ page contentType="text/html;charset=GB2312" language="java" %>
<html>
  <head><title>利用JavaI/O流读写文件</title></head>
  <body>
    <%
        //读取文件
        String fname=pageContext.getServletContext().getRealPath("8_5_1.txt");
        FileReader reader=new FileReader(fname);
        BufferedReader br=new BufferedReader(reader);
        String line;
        //读取文件的内容，显示到页面上
        while((line=br.readLine())!=null)
        {
            out.print(line+"<br/>");
        }
        //关闭流
        reader.close();
        br.close();

        //将数据写入文件
        String temp="写文件测试";
         fname=pageContext.getServletContext().getRealPath("out.txt");
        FileWriter fw=new FileWriter(fname);
        fw.write(temp);
        fw.close();

    %>
  </body>
</html>