package random;import java.io.RandomAccessFile;
import java.util.LinkedList;public class RandomFile {
    public RandomFile() {
    }
    void show(){
               
        try{
            int temp[]={12,31,56,23,27,1,43,65,4,99};
            RandomAccessFile readWrite=new RandomAccessFile("rand.dat","rw");
            for(int i=0;i<temp.length;i++){
                readWrite.writeInt(temp[i]);
            }
            System.out.println("逆向后为:");
            for(int i=temp.length-1;i>=0;i--){
                readWrite.seek(i*4);
                System.out.print(readWrite.readInt());
                if(i>0){
                    System.out.print(",");
                }
            }
            System.out.println();
        }
        catch(Exception ee){
            System.out.println("异常:"+ee);
        }
        finally{
            System.out.println("始终执行");
            System.out.println("在finally中执行");
        }
    }    public static void main(String[] args) {
        RandomFile randomfile = new RandomFile();
        randomfile.show();
    }
}

解决方案 »

  1.   

    看看这个类的声明: 
    public RandomAccessFile(java.lang.String arg0, java.lang.String arg1) throws java.io.FileNotFoundException; 它声明会可能会抛出FileNotFoundException,所以你必须显式捕获
      

  2.   

     查文档
    public RandomAccessFile(java.lang.String arg0, java.lang.String arg1) throws java.io.FileNotFoundException;  它声明会可能会抛出FileNotFoundException,文档说会抛出异常,你就必须对它进行处理!
    一般编译器都帮你解决这个问题