首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java相关 >

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

2013-03-27 
谁能帮我看一下这个程序哪错了,编译通过了,但运行时抛出异常:句柄无效。帮看看是哪错了应该怎么改改就行了。

谁能帮我看一下这个程序哪错了,
编译通过了,但运行时抛出异常:句柄无效。帮看看是哪错了应该怎么改改就行了。
源代码如下: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();把这句删了

热点排行