需求是将一个二进制文件读取
循环将文件中 每 118个字节 存放在Vector中,直到文件结束。

解决方案 »

  1.   

    public Vector readBinaryFile( String filePath )
      {
        Vector biVec = new Vector();
        FileInputStream biStream = null;
        try
        {
          File biFile = new File( filePath );
          //if (biFile.exists())
          if(biFile.exists() && biFile.isFile() && biFile.canRead())
           {
            //FileInputStream biStream = new FileInputStream( biFile );
            biStream = new FileInputStream( biFile );
            int len;
            byte[] biByte = new byte[118];
            while ( ( len = biStream.read( biByte, 0, 118 ) ) != -1 )
            {
              biVec.add( biByte );
            }
          }
        }catch( Exception e ){
          System.out.println(e.getMessage()); 
        }finally{
          try{
            if(biStream!=null) biStream.close();
          }catch(IOException e){
            System.out.println(e.getMessage());
          }
        }
        return biVec;
      }