有一个记录文件,是DataOutptStream生成,结构如下[[int 字符串长度][String 字符串]]*
现在要把他读进程序,但是每个块的长度不一样,如何检查到达结尾,有标准的办法吗?或者使用EOFException??

解决方案 »

  1.   

    就是我要用DataInputStream读取若干个数据块,但是每个数据块的大小不同,我不能预知结尾。如何在引发异常的情况下,让程序顺利读取到结尾,然后退出。
      

  2.   


    public static void main(String[] args) throws IOException{
     DataInputStream in=new DataInputStream(
         new BufferedInputStream(new FileInputStream("文件路径")));
     while(in.available()!=0)
     System.out.print((char)in.readByte());
    }