哪位高手能帮小弟我看一下这个程序哪错了

谁能帮我看一下这个程序哪错了,
编译通过了,但运行时抛出异常:句柄无效。帮看看是哪错了应该怎么改改就行了。
源代码如下:import java.io.*;
public class shiyan6_5
{
public static void main(String[] args)
{
String s="信110501班魏朝辉学号20112793";
RandomAccessFile inAndout=null;
try
{
inAndout=new RandomAccessFile("xinxi.txt","rw");
char []a=s.toCharArray();
inAndout.writeChars(s);
inAndout.close();
    long locate=0;
    long L=inAndout.length();
    inAndout.seek(locate);
    while(locate<L)
    {
     String str=inAndout.readLine();
     byte b[]=str.getBytes("iso-8859-1");
        
     str=new String(b,"GB2312");
     inAndout.close();
     System.out.println(str);
;      }
}
catch(IOException e)
{
System.out.println("存在如下异常:");
System.out.println(e.getMessage());
}
}
}
有老大家了。
------解决方案--------------------
inAndout=new RandomAccessFile("xinxi.txt","rw");

------解决方案--------------------
出现句柄无效的问题 是因为 你之前先把流关闭掉了
inAndout.close();
建议,异常打印用e.printStackTrace(); 可以 清楚看到问题出现在什么地方
------解决方案--------------------
inAndout.close();把这句删了