<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.io.*"%>
<html>
<head>
<title>使用RandomAccessFile</title>
</head>
<body>
<center>
<%
    try{
         File f1=new File("c:/tom5.txt");
 int data[]={1,2,3,4,5,6,7,8,9,10};
 RandomAccessFile raf=new RandomAccessFile(f1,"rw");
 for(int i=0;i<data.length;i++)
 {
   raf.writeInt(data[i]);
   }
   /**
        一个int数据占4个字节,从文件的第36个字节读取最后面的一个整数每隔4个字节往前读取一个整数。*/
for(int i=data.length-1;i>=0;i--){
 raf.seek(i*4);
 out.println(raf.readInt());
 }
 raf.close();
 }
 catch(IOException e){
  out.println(e);
  }
  %>
  </center>
  </body>
  </html>代码中虽然也注释说明了,但我还是不是很懂,"data.length"的长度不是10吗,为什么要减1才能从尾循环哪(如果不减1,就报错)。减1不是从9开始循环了吗?第36个字节不就是从9开始吗?我这人逻辑不是很强,让大家见笑了。希望大家指点一二。