<%--List8_5_2.jsp--%>
<%@ page import="java.io.RandomAccessFile"%>
<%@ page contentType="text/html;charset=GB2312" language="java" %>
<html>
  <head><title>利用JavaI/O流读写文件</title></head>
  <body>
    <%
        String fname=pageContext.getServletContext().getRealPath("8_5_2.txt");
        RandomAccessFile raf=new RandomAccessFile(fname,"rw");
        //在文件为追加数据
        raf.seek(raf.length());
        raf.writeUTF("王五");
        raf.writeInt(28);
        raf.writeDouble(128.33);
        raf.close();
        raf=new RandomAccessFile(fname,"rw");
        raf.seek(0);
        out.println("Name:"+raf.readUTF()+"<br/>");
        out.println("Age:"+raf.readInt()+"<br/>");
        out.println("Weight:"+raf.readDouble()+"<br/>");
        raf.close();
    %>
  </body>
</html>