Text File Read/Write

mikeyjb8

New member
Joined
Apr 5, 2010
Messages
2
Programming Experience
5-10
Hello All,

I just had a small question regarding reading and writing a text file.

I have a program that reads lines out of a text file and writes them out to a new version of the file, changing text in there (same amount of digits).

But the new file it creates is smaller than the original file, although the contents looks the same.

Does anyone know why?

Regards,

Mike
 
Without more information, the only thing I can think of is that the original file is storing two bytes per character and the new file is storing one byte per character.
 
More Detail...

I am opening an existing file i.e. 00123456.001 using "fileopen".

I split each line into 3 variables, sStart sValue and sEnd

I make changes to sValue (same character length tho)

I then at the same time open a new file (to output to) and write the edited line in as below:

Printline(1, sStart & sValue & sEnd)

The filesize is slightly smaller when this gets through. Yet the data inside is excactly the same:

Contents of a file as follows

30600784000100024853114032010174426000030119 002130
30200784000100024853114032010174426000030119 010000300
30900784000100024853114032010174426000030119 00000000
 
First up, you should ditch that VB6-style of I/O. Use the members of the System.IO namespace. For text files you can use the StreamReader and StreamWriter classes, the TextFieldParser class and the File.ReadAllText, .ReadAllLines, etc, methods. For binary files you can use the FileStream class and the File.ReadAllBytes and .WriteAllBytes methods.
 
Back
Top