変換バッファのオーバーフローを回避するには?


DELL  2004-05-26 20:49:59  No: 113537  IP: [192.*.*.*]

以下はバイナリファイルを読み込んで分割するロジックの一部ですが
このプログラムを実行すると

ERR.NUMBER=5
mscorlib
変換バッファのオーバーフローです。

と出てしまいます。
回避方法が検討つきません。
どなたかご教授ください。
環境はVB.NETです。
-------------------------------------------------
Do

     'バイナリファイルを256バイトずつ読み込む
     ibuf = iBr.ReadBytes(READ_BYTES)
     If iBr.PeekChar = -1 Then
        Exit Do
     End If

     '読み込んだByte配列をテキストに変換
      strBuf = System.BitConverter.ToString(ibuf)

     'バイナリファイルをパターンマッチング
      If InStr(strBuf, SEARCH_VALUE) <> 0 Then

          '区切りレコードを読み飛ばし
           ibuf = iBr.ReadBytes(READ_BYTES)
           If iBr.PeekChar = -1 Then
               Exit Do
           End If

           oBr.Close()
           ofs.Close()

          '出力ファイル用カウンタ
           intFile = intFile + 1

          '出力用ファイル名
           stroPath = CmdArgs(1) & "\" & "PrintFile" & Format(intFile, "000")

           '新たに出力用FileStream/BinaryWriter構築
           ofs = New System.IO.FileStream(stroPath, System.IO.FileMode.Create)

           oBr = New System.IO.BinaryWriter(ofs)

           Console.WriteLine(stroPath & "を出力中です。")

      End If

                '帳票ファイルを出力する
                oBr.Write(ibuf)<**************ここでオーバーフロー発生

Loop
-------------------------------------------------------------

編集 削除
DELL  2004-05-27 09:46:25  No: 113538  IP: [192.*.*.*]

バイナリリーダー、バイナリライターを使用して
読み込み書き込みをしているのですが
実行時エラーの発生していた以下のコードを
コメントにして、バイナリファイルの読み込みだけにしても
同様のエラーになっています。

oBr.Write(ibuf)

読み込み時のバイト配列を小さく指定してやってみます。




--------------------------------------------------------------
以下は宣言の部分です。

            '入力ファイルのFileStream構築
            Dim ifs As New System.IO.FileStream(CmdArgs(0), System.IO.FileMode.Open)
            '入力ファイルのBinaryReader構築
            Dim iBr As New System.IO.BinaryReader(ifs)
            'BinaryReader.Read バッファ/配列インデックス
            Dim ibuf() As Byte
            Dim iidx As Integer

            '出力ファイル用バッファ/変数
            Dim intBuf() As Integer
            Dim strBuf As String
            Dim stroPath As String
            Dim intFile As Integer
            Dim i As Integer

            '入力ファイルの先頭へ移動/変数初期化
            iBr.BaseStream.Seek(0, IO.SeekOrigin.Begin)
            iidx = 0
            intFile = 0

            '出力ファイル用カウンタ
            intFile = intFile + 1
            '出力用ファイル名
            stroPath = CmdArgs(1) & "\" & "PrintFile" & Format(intFile, "000")

            '出力ファイルのFileStream構築
            Dim ofs As New System.IO.FileStream(stroPath, System.IO.FileMode.Create)
            '出力ファイルのBinaryReader構築
            Dim oBr As New System.IO.BinaryWriter(ofs)

編集 削除