VB.NETのBinaryReaderで読み込みを行うと、8,145,157Byte目で「変換バッファのオーバーフローです」のエラーがでます。
それよりも小さいファイルですと発生しません。
何か環境設定でも必要なのでしょうか。
よろしくお願いいたします。
Dim fsi As System.IO.FileStream = New System.IO.FileStream(TextBoxPath.Text, IO.FileMode.Open)
Dim br As System.IO.BinaryReader = New System.IO.BinaryReader(fsi)
Dim aBuf As Byte
lCntCopy = 0
Do While br.PeekChar() <> -1
aBuf = br.ReadByte
bw.Write(aBuf)
lCntCopy = lCntCopy + 1
Loop
過去ログで
http://madia.world.coocan.jp/vb/vb_bbs2/200405_04050117.html
を見つけましたが参考になりますか?
このログも同じ症状ですね。
投稿だけで何も解決していないです。
VB.NETのBinaryReaderのバグとしか思えません。
諦めて他の方法でバイナリファイルを扱うことになりそうですね。
はじめまして。
同様の現象が発生しましたが、解決できましたので書き込みます。
結論から書きますと
> Do While br.PeekChar() <> -1
を
> Do While br.BaseStream.Position < br.BaseStream.Length
としたら動作しました。
当方のExceptionの内容です。
{System.ArgumentException}
[System.ArgumentException]: {System.ArgumentException}
HelpLink: Nothing
InnerException: Nothing
Message: "変換バッファのオーバーフローです。"
Source: "mscorlib"
StackTrace: " at System.Text.UTF8Encoding.GetChars(Byte[] bytes, Int32 byteIndex, Int32 byteCount, Char[] chars, Int32 charIndex, UTF8Decoder decoder)
at System.Text.UTF8Decoder.GetChars(Byte[] bytes, Int32 byteIndex, Int32 byteCount, Char[] chars, Int32 charIndex)
at System.IO.BinaryReader.InternalReadOneChar()
at System.IO.BinaryReader.Read()
at System.IO.BinaryReader.PeekChar()
よくわかりませんが、UTF8へのエンコードで不正なキャラクタがあるようです。
同一のファイルだと同一の場所で発生します。ですので、何バイト目にExceptionが発生するかは元のファイルによります。
ツイート | ![]() |