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();
}
}
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();
}
}
public RandomAccessFile(java.lang.String arg0, java.lang.String arg1) throws java.io.FileNotFoundException;它声明会可能会抛出FileNotFoundException,所以你必须显式捕获