Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Losing 3KB when Wrting 1

Status
Not open for further replies.

CodingIsFun

Programmer
Apr 9, 2004
134
US
Hi all experts,

Maybe Im missing something. I am reading then writing to a file.

I have a 4GB file that I am processing. The resulting file is missing 3KB. I am having a problem comparing the files because it is so big. Here is my code.

StreamReader reader = new StreamReader(file_name, Encoding.UTF8, false, 100000);
StreamWriter converted_file = new StreamWriter(file_name_out, false, Encoding.UTF8, 100000);
converted_file.AutoFlush = true;
while (!reader.EndOfStream)
{
converted_file.Write(reader.ReadLine());
}

reader.Close();
reader.Dispose();
converted_file.Flush();
converted_file.Close();
converted_file.Dispose();

I have used this on a 400MB file and there is no loss of data.

Any help would be greatly appreciated..

Thanks in advance..

 
are you sure the size you are looking at is actual size of the files, not "size on disk" which is sometimes shown. And since files are usually stored in blocks of 4k, a variance of less than 4k can be expected with regards to size on disk.

Also, just to be on the safe side, move the reader.close and reader.dispose to after the Flush()
 


The actual size dif is 2518 bytes. I am going to break down each file into small pieces so I can do a diff on them.

thanks for the help.
 
You might also want to look at possible differences in how line-separators are being handled.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Thanks ChipH..

That was the issue. I am reading in by carriage returns and writing out with none.

Now the file sizes are the same.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top