public static void main(String[] args) {
RandomAccessFile file = null;
try {
file = new RandomAccessFile("tom.dat", "rw");
for (int i = 1; i < 11; i++)
file.writeInt(i);
long p = file.getFilePointer();
for (int i= 1; i < 11; i++){
file.seek(p - i * 4);
System.out.println(file.readInt());
}
} catch (Exception e) {
// TODO: handle exception
} finally {
try {
if (file != null) {
file.close();
}
} catch (IOException IgnoreWhenClose) {
}
}
}

解决方案 »

  1.   

    这是dat的内容,16进制的: 
    00 00 00 01 00 00 00 02 00 00 00 03 00 00 00 04 00 00 00 05 00 00 00 06 00 00 00 07 00 00 00 08 00 00 00 09 00 00 00 0a
    至于题意,就看你怎么理解了
      

  2.   

    int[] intstr = {1,2,3,4,5,6,7};
    String[] sstr = new String[intstr.length];
    for(int i=0; i<intstr.length; i++){
       sstr[i] = String.valueOf(intstr[i]);
    }
    这样就可以获得一个{1,2,3,4,5,6,7}的String类型数组了,然后你向文件里输出就行。应该是楼主要的东西了吧
      

  3.   

    public class Test3 {
     public static void main(String args[]){
     try{
     RandomAccessFile raf = new RandomAccessFile("D:/JavaTest/tom.dat","rw");
     for(int i=1;i<=10;i++){
     raf.writeInt(i);
     }
     int fileIndex=(int) (raf.length()-4);
     for(int i=1;i<=10;i++){
     raf.seek(fileIndex);
      System.out.println(raf.readInt());
      fileIndex-=4;
     }
     }catch(IOException e){
     e.printStackTrace();
     }
     }
    }