G
Guest
Hi all,
I am reading a 240MB+ binary file performing some changes and writing it
back out. For now I have removed the code that performs changes so in its
simplistic form reading a large binary and then writing it back out.
After about 4MB I receive an exception:
The output char buffer is too small to contain the decoded characters,
encoding 'Unicode' fallback 'System.Text.DecoderReplacementFallback'.
Parameter name: chars
I really cant figure this one out. Code is below ( I put the flushes in
hoping that was the problem)
try
{
//Open the source file
sourcestream = SourceFile.Open(FileMode.Open,
FileAccess.Read, FileShare.None);
//open the output file
targetstream = TargetFile.Open(FileMode.CreateNew,
FileAccess.Write, FileShare.None);
breader = new BinaryReader(sourcestream);
bwriter = new BinaryWriter(targetstream);
for (long i = 0; i < SourceFile.Length; i++)
{
bwriter.Write(breader.Read());
if (i % 2000 == 0)
{
bwriter.Flush();
targetstream.Flush();
}
}
breader.Close();
sourcestream.Close();
bwriter.Close();
targetstream.Close();
//Delete the original source file
SourceFile.Delete();
Any help would be greatly appreciated
Regards, Pete.
I am reading a 240MB+ binary file performing some changes and writing it
back out. For now I have removed the code that performs changes so in its
simplistic form reading a large binary and then writing it back out.
After about 4MB I receive an exception:
The output char buffer is too small to contain the decoded characters,
encoding 'Unicode' fallback 'System.Text.DecoderReplacementFallback'.
Parameter name: chars
I really cant figure this one out. Code is below ( I put the flushes in
hoping that was the problem)
try
{
//Open the source file
sourcestream = SourceFile.Open(FileMode.Open,
FileAccess.Read, FileShare.None);
//open the output file
targetstream = TargetFile.Open(FileMode.CreateNew,
FileAccess.Write, FileShare.None);
breader = new BinaryReader(sourcestream);
bwriter = new BinaryWriter(targetstream);
for (long i = 0; i < SourceFile.Length; i++)
{
bwriter.Write(breader.Read());
if (i % 2000 == 0)
{
bwriter.Flush();
targetstream.Flush();
}
}
breader.Close();
sourcestream.Close();
bwriter.Close();
targetstream.Close();
//Delete the original source file
SourceFile.Delete();
Any help would be greatly appreciated
Regards, Pete.