By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,363 Members | 2,961 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,363 IT Pros & Developers. It's quick & easy.

Discrepancies between FileGet and StreamReader

P: n/a
Hello:

When I use either one to read a Text file, I get the same result. The length
of the string that the file's content has been written into is the same.

However, if the file is binary, FileGet gets me the correct content while
StreamReader gives me a truncated string.

Can somebody advise me why? Should I be using BinaryReader instead of
StreamReader? Would BinaryReader work on text files?

Venkat
Nov 21 '05 #1
Share this Question
Share on Google+
16 Replies


P: n/a
I tried using BinayReader but unlike the simplicity of the one single
statement as follows:

FileGet(ciFileHandle, sFileContent)

which will read the contents of the file into sFileContent, I have to read
one byte at a time and concatenate to sFileContent.

Is there one Stream/Binary class that will work both on text and binary files?
Nov 21 '05 #2

P: n/a
"vvenk" <vv***@discussions.microsoft.com> schrieb:
Can somebody advise me why? Should I be using
BinaryReader instead of StreamReader?
Depends on what you want to do. Notice that you can specify an encoding in
the 'StreamReader''s constructor.
Would BinaryReader work on text files?


Yes.

\\\
Dim br As New System.IO.BinaryReader( _
New System.IO.FileStream("C:\foo.txt", IO.FileMode.Open) _
)
Dim abyt() As Byte = br.ReadBytes(br.BaseStream.Length)
br.Close()
Dim s As String = System.Text.Encoding.Default.GetString(abyt)
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 21 '05 #3

P: n/a
Herfried:

Thank you so much for your tip. The BinaryReader, in my view, is more
versatile in that it handles different encoding.

Venkat

"Herfried K. Wagner [MVP]" wrote:
"vvenk" <vv***@discussions.microsoft.com> schrieb:
Can somebody advise me why? Should I be using
BinaryReader instead of StreamReader?


Depends on what you want to do. Notice that you can specify an encoding in
the 'StreamReader''s constructor.
Would BinaryReader work on text files?


Yes.

\\\
Dim br As New System.IO.BinaryReader( _
New System.IO.FileStream("C:\foo.txt", IO.FileMode.Open) _
)
Dim abyt() As Byte = br.ReadBytes(br.BaseStream.Length)
br.Close()
Dim s As String = System.Text.Encoding.Default.GetString(abyt)
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 21 '05 #4

P: n/a
"vvenk" <vv***@discussions.microsoft.com> schrieb:
Thank you so much for your tip. The BinaryReader, in my view,
is more versatile in that it handles different encoding.


The streamreader can handle different encodings too, and thus is more
high-level when reading text files.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 21 '05 #5

P: n/a
Herfried:

Thanks to you, I am able to read a binary file and store its contents into a
string:

Dim lfsTemp = New FileStream("Original.INI", IO.FileMode.Open)
Dim lbrTemp = New BinaryReader(lfsTemp)
Dim lbTemp = lbrTemp.ReadBytes(lbrTemp.BaseStream.Length)
Dim sFileContent as String =
System.Text.Encoding.Default.GetString(lbTemp)

I tried saving sFileContent to a new file:

Dim lfsTemp As New FileStream("Copy.Ini", FileMode.CreateNew)
Dim lbwTemp As New BinaryWriter(lfsTemp)

SaveFile = False

lbwTemp.Write(sFileContent)
lbwTemp.Close()
lfsTemp.Close()
I see that the two file sizes are not the same.

Can you tell me why?

Venkat

Nov 21 '05 #6

P: n/a
"vvenk" <vv***@discussions.microsoft.com> schrieb:
Thanks to you, I am able to read a binary file and
store its contents into a
string:

Dim lfsTemp = New FileStream("Original.INI", IO.FileMode.Open)
Dim lbrTemp = New BinaryReader(lfsTemp)
Dim lbTemp = lbrTemp.ReadBytes(lbrTemp.BaseStream.Length)
Dim sFileContent as String =
System.Text.Encoding.Default.GetString(lbTemp)

I tried saving sFileContent to a new file:

Dim lfsTemp As New FileStream("Copy.Ini", FileMode.CreateNew)
Dim lbwTemp As New BinaryWriter(lfsTemp)

SaveFile = False

lbwTemp.Write(sFileContent)
lbwTemp.Close()
lfsTemp.Close()
I see that the two file sizes are not the same.

Can you tell me why?


I assume that different encodings are used. If the source file is encoded
in your default code page, then you need 'Encoding.Default' to read it.
Notice that the binary reader does not know that it should use
'Encoding.Default' too to decompose the string into a byte array.
'BinaryWriter' provides a constructor that accepts an encoding:

\\\
Dim br As New BinaryWriter(..., Encoding.Default)
....
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 21 '05 #7

P: n/a
John:

As per your advice, I modified my write statement:

Dim lbwTemp As New BinaryWriter(lfsTemp, System.Text.Encoding.Default)

But I have the following differences:

1. The Original file content is 1205 bytes; the copy file contents is 1207
bytes.
2. I checked the ASC of first character; in Orginal it's 146 and in the
Copy, it's 181.

I see that when reading the file, I had used the following statement to
convert byte to string:

Dim sFileContent as String =
System.Text.Encoding.Default.GetString(lbTemp)

Should I be converting the string to byte before I write it to the file? If
so, can you help me with the syntax?

Thanks for your continued help.

Venkat

"Herfried K. Wagner [MVP]" wrote:
"vvenk" <vv***@discussions.microsoft.com> schrieb:
Thanks to you, I am able to read a binary file and
store its contents into a
string:

Dim lfsTemp = New FileStream("Original.INI", IO.FileMode.Open)
Dim lbrTemp = New BinaryReader(lfsTemp)
Dim lbTemp = lbrTemp.ReadBytes(lbrTemp.BaseStream.Length)
Dim sFileContent as String =
System.Text.Encoding.Default.GetString(lbTemp)

I tried saving sFileContent to a new file:

Dim lfsTemp As New FileStream("Copy.Ini", FileMode.CreateNew)
Dim lbwTemp As New BinaryWriter(lfsTemp)

SaveFile = False

lbwTemp.Write(sFileContent)
lbwTemp.Close()
lfsTemp.Close()
I see that the two file sizes are not the same.

Can you tell me why?


I assume that different encodings are used. If the source file is encoded
in your default code page, then you need 'Encoding.Default' to read it.
Notice that the binary reader does not know that it should use
'Encoding.Default' too to decompose the string into a byte array.
'BinaryWriter' provides a constructor that accepts an encoding:

\\\
Dim br As New BinaryWriter(..., Encoding.Default)
....
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 21 '05 #8

P: n/a
"vvenk" <vv***@discussions.microsoft.com> schrieb:
Should I be converting the string to byte before I write it to the file?
If
so, can you help me with the syntax?

You can try to do that:

\\\
Dim abyt() As Byte = _
System.Text.Encoding.Default.GetBytes(Content)
....
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 21 '05 #9

P: n/a
Herbert:

I viewed the two files. The copy has two extra bytes added to the front.
That accounts for the difference in size. Let me try converting the string to
a byte and then saving it.

Thanks again.

venkat

"Herfried K. Wagner [MVP]" wrote:
"vvenk" <vv***@discussions.microsoft.com> schrieb:
Should I be converting the string to byte before I write it to the file?
If
so, can you help me with the syntax?

You can try to do that:

\\\
Dim abyt() As Byte = _
System.Text.Encoding.Default.GetBytes(Content)
....
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 21 '05 #10

P: n/a
Herbert:

Yes! That did it. Thank you sooooo much.

venkat

"Herfried K. Wagner [MVP]" wrote:
"vvenk" <vv***@discussions.microsoft.com> schrieb:
Should I be converting the string to byte before I write it to the file?
If
so, can you help me with the syntax?

You can try to do that:

\\\
Dim abyt() As Byte = _
System.Text.Encoding.Default.GetBytes(Content)
....
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 21 '05 #11

P: n/a
"vvenk" <vv***@discussions.microsoft.com> schrieb:
Herbert:

^^^

Who is that?

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 21 '05 #12

P: n/a
Herfried:

I am so sorry. Coincidentally, I just finished talking to someone named
Herbert and the name was apparently etched into my short-term memory!

Venkat

"Herfried K. Wagner [MVP]" wrote:
"vvenk" <vv***@discussions.microsoft.com> schrieb:
Herbert:

^^^

Who is that?

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 21 '05 #13

P: n/a
Venkat
In addition to Herfried's excellent help.
I see that the two file sizes are not the same.

Can you tell me why?
BinaryWriter has overloaded Write methods, you asked to write a String.
BinaryWriter.Write(String) writes the encoded length of the string first,
followed by the contents of the string.

Based on your example you are only reading & writing text, I would recommend
using StreamReader & StreamWriter, they specialize in reading & writing text
to a file.

BinaryReader & BinaryWriter specialize in reading & writing stuff in binary
(its native bit format, aka bytes). For example Binary.Write(Integer) will
write four bytes that make up an Integer, BinaryWriter(Long) will write 8
bytes, where as StreamWriter.Write(Integer) will format the Integer as text,
then write the chars that make up that text.

To really see the difference compare the overloaded Write methods on
BinaryWriter:

http://msdn.microsoft.com/library/de...WriteTopic.asp

With the overloaded Write methods on StreamWriter:

http://msdn.microsoft.com/library/de...WriteTopic.asp

Notice that BinaryWriter has all the "built-in" types, while StreamWriter
only as Char & String.

So using Stream Reader & Writer instead of Binary Reader & Writer you have:
Dim lfsTemp = New FileStream("Original.INI", IO.FileMode.Open)
Dim lbrTemp = New BinaryReader(lfsTemp)
Dim lbTemp = lbrTemp.ReadBytes(lbrTemp.BaseStream.Length)
Dim sFileContent as String =
System.Text.Encoding.Default.GetString(lbTemp)
Dim lbrTemp As New StreamReader("Original.INI", Encoding.Default)
Dim sFileContent As String = lbrTemp.ReadToEnd()

While:
Dim lfsTemp As New FileStream("Copy.Ini", FileMode.CreateNew)
Dim lbwTemp As New BinaryWriter(lfsTemp)

SaveFile = False

lbwTemp.Write(sFileContent)
With a StreamWriter is:

Dim lbwTemp As New StreamWriter("Copy.Ini", False, Encoding.Default)
lbwTemp.Write(sFileContent)

SaveFile = False

Note you can pass the file name directly to the constructor of BinaryReader,
BinaryWriter, StreamReader & StreamWriter. You don't have to create a
FileStream first...
Hope this helps
Jay
"vvenk" <vv***@discussions.microsoft.com> wrote in message
news:4F**********************************@microsof t.com... Herfried:

Thanks to you, I am able to read a binary file and store its contents into
a
string:

Dim lfsTemp = New FileStream("Original.INI", IO.FileMode.Open)
Dim lbrTemp = New BinaryReader(lfsTemp)
Dim lbTemp = lbrTemp.ReadBytes(lbrTemp.BaseStream.Length)
Dim sFileContent as String =
System.Text.Encoding.Default.GetString(lbTemp)

I tried saving sFileContent to a new file:

Dim lfsTemp As New FileStream("Copy.Ini", FileMode.CreateNew)
Dim lbwTemp As New BinaryWriter(lfsTemp)

SaveFile = False

lbwTemp.Write(sFileContent)
lbwTemp.Close()
lfsTemp.Close()
I see that the two file sizes are not the same.

Can you tell me why?

Venkat

Nov 21 '05 #14

P: n/a
Jay:

Thank you for the additional help.

I am not reading and writing text. The file content is encrypted using a
custom algorithm and so, I need to be able to read the bytes.

Venkat

"Jay B. Harlow [MVP - Outlook]" wrote:
Venkat
In addition to Herfried's excellent help.
I see that the two file sizes are not the same.

Can you tell me why?


BinaryWriter has overloaded Write methods, you asked to write a String.
BinaryWriter.Write(String) writes the encoded length of the string first,
followed by the contents of the string.

Based on your example you are only reading & writing text, I would recommend
using StreamReader & StreamWriter, they specialize in reading & writing text
to a file.

BinaryReader & BinaryWriter specialize in reading & writing stuff in binary
(its native bit format, aka bytes). For example Binary.Write(Integer) will
write four bytes that make up an Integer, BinaryWriter(Long) will write 8
bytes, where as StreamWriter.Write(Integer) will format the Integer as text,
then write the chars that make up that text.

To really see the difference compare the overloaded Write methods on
BinaryWriter:

http://msdn.microsoft.com/library/de...WriteTopic.asp

With the overloaded Write methods on StreamWriter:

http://msdn.microsoft.com/library/de...WriteTopic.asp

Notice that BinaryWriter has all the "built-in" types, while StreamWriter
only as Char & String.

So using Stream Reader & Writer instead of Binary Reader & Writer you have:
Dim lfsTemp = New FileStream("Original.INI", IO.FileMode.Open)
Dim lbrTemp = New BinaryReader(lfsTemp)
Dim lbTemp = lbrTemp.ReadBytes(lbrTemp.BaseStream.Length)
Dim sFileContent as String =
System.Text.Encoding.Default.GetString(lbTemp)


Dim lbrTemp As New StreamReader("Original.INI", Encoding.Default)
Dim sFileContent As String = lbrTemp.ReadToEnd()

While:
Dim lfsTemp As New FileStream("Copy.Ini", FileMode.CreateNew)
Dim lbwTemp As New BinaryWriter(lfsTemp)

SaveFile = False

lbwTemp.Write(sFileContent)


With a StreamWriter is:

Dim lbwTemp As New StreamWriter("Copy.Ini", False, Encoding.Default)
lbwTemp.Write(sFileContent)

SaveFile = False

Note you can pass the file name directly to the constructor of BinaryReader,
BinaryWriter, StreamReader & StreamWriter. You don't have to create a
FileStream first...
Hope this helps
Jay
"vvenk" <vv***@discussions.microsoft.com> wrote in message
news:4F**********************************@microsof t.com...
Herfried:

Thanks to you, I am able to read a binary file and store its contents into
a
string:

Dim lfsTemp = New FileStream("Original.INI", IO.FileMode.Open)
Dim lbrTemp = New BinaryReader(lfsTemp)
Dim lbTemp = lbrTemp.ReadBytes(lbrTemp.BaseStream.Length)
Dim sFileContent as String =
System.Text.Encoding.Default.GetString(lbTemp)

I tried saving sFileContent to a new file:

Dim lfsTemp As New FileStream("Copy.Ini", FileMode.CreateNew)
Dim lbwTemp As New BinaryWriter(lfsTemp)

SaveFile = False

lbwTemp.Write(sFileContent)
lbwTemp.Close()
lfsTemp.Close()
I see that the two file sizes are not the same.

Can you tell me why?

Venkat


Nov 21 '05 #15

P: n/a
Venkat,
You may want to use a Stream directly & forgo BinaryReader or StreamReader
then.

I would consider creating an EncryptedStream (see composing streams below)
that inherits from Stream and overrides Stream.Read & Stream.Write to do the
encryption & decryption for me. Similar to
System.SecruityCryptography.CryptoStream. Note EncryptedStream would not be
based on FileStream.

Then depending on whether the encrypted contents is Binary or Text, I would
use a BinaryReader or StreamReader over a EncryptedStream.

Something Like:
> Dim lfsTemp = New FileStream("Original.INI",
> IO.FileMode.Open)
Dim stream As New EncryptedStream(lfsTemp)

Dim reader As New StreamReader(stream)

Dim writer As New StreamWriter(stream)

By basing EncryptedStream on Steam itself, you can use EncryptedStream with
a NetworkStream or other kinds of stream & still encrypt & decrypt data from
them.

The following section of MSDN discusses streams and readers & writers:

http://msdn.microsoft.com/library/de...kingwithio.asp

This page discusses composing streams (what I am suggesting above), but I
think could use a better example:
http://msdn.microsoft.com/library/de...ingstreams.asp

Basically EncryptedStream would be a pass-through stream that provides the
encryption & decryption that you need, most of its methods would pass
through to its base stream, while some (read & write) would do the
decryption & encryption.

Hope this helps
Jay
"vvenk" <vv***@discussions.microsoft.com> wrote in message
news:CF**********************************@microsof t.com... Jay:

Thank you for the additional help.

I am not reading and writing text. The file content is encrypted using a
custom algorithm and so, I need to be able to read the bytes.

Venkat

"Jay B. Harlow [MVP - Outlook]" wrote:
Venkat
In addition to Herfried's excellent help.
> I see that the two file sizes are not the same.
>
> Can you tell me why?


BinaryWriter has overloaded Write methods, you asked to write a String.
BinaryWriter.Write(String) writes the encoded length of the string first,
followed by the contents of the string.

Based on your example you are only reading & writing text, I would
recommend
using StreamReader & StreamWriter, they specialize in reading & writing
text
to a file.

BinaryReader & BinaryWriter specialize in reading & writing stuff in
binary
(its native bit format, aka bytes). For example Binary.Write(Integer)
will
write four bytes that make up an Integer, BinaryWriter(Long) will write 8
bytes, where as StreamWriter.Write(Integer) will format the Integer as
text,
then write the chars that make up that text.

To really see the difference compare the overloaded Write methods on
BinaryWriter:

http://msdn.microsoft.com/library/de...WriteTopic.asp

With the overloaded Write methods on StreamWriter:

http://msdn.microsoft.com/library/de...WriteTopic.asp

Notice that BinaryWriter has all the "built-in" types, while StreamWriter
only as Char & String.

So using Stream Reader & Writer instead of Binary Reader & Writer you
have:
> Dim lfsTemp = New FileStream("Original.INI",
> IO.FileMode.Open)
> Dim lbrTemp = New BinaryReader(lfsTemp)
> Dim lbTemp = lbrTemp.ReadBytes(lbrTemp.BaseStream.Length)
> Dim sFileContent as String =
> System.Text.Encoding.Default.GetString(lbTemp)


Dim lbrTemp As New StreamReader("Original.INI", Encoding.Default)
Dim sFileContent As String = lbrTemp.ReadToEnd()

While:
> Dim lfsTemp As New FileStream("Copy.Ini", FileMode.CreateNew)
> Dim lbwTemp As New BinaryWriter(lfsTemp)
>
> SaveFile = False
>
> lbwTemp.Write(sFileContent)


With a StreamWriter is:

Dim lbwTemp As New StreamWriter("Copy.Ini", False, Encoding.Default)
lbwTemp.Write(sFileContent)

SaveFile = False

Note you can pass the file name directly to the constructor of
BinaryReader,
BinaryWriter, StreamReader & StreamWriter. You don't have to create a
FileStream first...
Hope this helps
Jay
"vvenk" <vv***@discussions.microsoft.com> wrote in message
news:4F**********************************@microsof t.com...
> Herfried:
>
> Thanks to you, I am able to read a binary file and store its contents
> into
> a
> string:
>
> Dim lfsTemp = New FileStream("Original.INI",
> IO.FileMode.Open)
> Dim lbrTemp = New BinaryReader(lfsTemp)
> Dim lbTemp = lbrTemp.ReadBytes(lbrTemp.BaseStream.Length)
> Dim sFileContent as String =
> System.Text.Encoding.Default.GetString(lbTemp)
>
> I tried saving sFileContent to a new file:
>
> Dim lfsTemp As New FileStream("Copy.Ini", FileMode.CreateNew)
> Dim lbwTemp As New BinaryWriter(lfsTemp)
>
> SaveFile = False
>
> lbwTemp.Write(sFileContent)
> lbwTemp.Close()
> lfsTemp.Close()
>
>
> I see that the two file sizes are not the same.
>
> Can you tell me why?
>
> Venkat
>


Nov 21 '05 #16

P: n/a
Jay:

Thank you for your elegant solution. It works like a charm.

Venkat

"Jay B. Harlow [MVP - Outlook]" wrote:
Venkat,
You may want to use a Stream directly & forgo BinaryReader or StreamReader
then.

I would consider creating an EncryptedStream (see composing streams below)
that inherits from Stream and overrides Stream.Read & Stream.Write to do the
encryption & decryption for me. Similar to
System.SecruityCryptography.CryptoStream. Note EncryptedStream would not be
based on FileStream.

Then depending on whether the encrypted contents is Binary or Text, I would
use a BinaryReader or StreamReader over a EncryptedStream.

Something Like:
> Dim lfsTemp = New FileStream("Original.INI",
> IO.FileMode.Open)

Dim stream As New EncryptedStream(lfsTemp)

Dim reader As New StreamReader(stream)

Dim writer As New StreamWriter(stream)

By basing EncryptedStream on Steam itself, you can use EncryptedStream with
a NetworkStream or other kinds of stream & still encrypt & decrypt data from
them.

The following section of MSDN discusses streams and readers & writers:

http://msdn.microsoft.com/library/de...kingwithio.asp

This page discusses composing streams (what I am suggesting above), but I
think could use a better example:
http://msdn.microsoft.com/library/de...ingstreams.asp

Basically EncryptedStream would be a pass-through stream that provides the
encryption & decryption that you need, most of its methods would pass
through to its base stream, while some (read & write) would do the
decryption & encryption.

Hope this helps
Jay
"vvenk" <vv***@discussions.microsoft.com> wrote in message
news:CF**********************************@microsof t.com...
Jay:

Thank you for the additional help.

I am not reading and writing text. The file content is encrypted using a
custom algorithm and so, I need to be able to read the bytes.

Venkat

"Jay B. Harlow [MVP - Outlook]" wrote:
Venkat
In addition to Herfried's excellent help.

> I see that the two file sizes are not the same.
>
> Can you tell me why?

BinaryWriter has overloaded Write methods, you asked to write a String.
BinaryWriter.Write(String) writes the encoded length of the string first,
followed by the contents of the string.

Based on your example you are only reading & writing text, I would
recommend
using StreamReader & StreamWriter, they specialize in reading & writing
text
to a file.

BinaryReader & BinaryWriter specialize in reading & writing stuff in
binary
(its native bit format, aka bytes). For example Binary.Write(Integer)
will
write four bytes that make up an Integer, BinaryWriter(Long) will write 8
bytes, where as StreamWriter.Write(Integer) will format the Integer as
text,
then write the chars that make up that text.

To really see the difference compare the overloaded Write methods on
BinaryWriter:

http://msdn.microsoft.com/library/de...WriteTopic.asp

With the overloaded Write methods on StreamWriter:

http://msdn.microsoft.com/library/de...WriteTopic.asp

Notice that BinaryWriter has all the "built-in" types, while StreamWriter
only as Char & String.

So using Stream Reader & Writer instead of Binary Reader & Writer you
have:

> Dim lfsTemp = New FileStream("Original.INI",
> IO.FileMode.Open)
> Dim lbrTemp = New BinaryReader(lfsTemp)
> Dim lbTemp = lbrTemp.ReadBytes(lbrTemp.BaseStream.Length)
> Dim sFileContent as String =
> System.Text.Encoding.Default.GetString(lbTemp)

Dim lbrTemp As New StreamReader("Original.INI", Encoding.Default)
Dim sFileContent As String = lbrTemp.ReadToEnd()

While:

> Dim lfsTemp As New FileStream("Copy.Ini", FileMode.CreateNew)
> Dim lbwTemp As New BinaryWriter(lfsTemp)
>
> SaveFile = False
>
> lbwTemp.Write(sFileContent)

With a StreamWriter is:

Dim lbwTemp As New StreamWriter("Copy.Ini", False, Encoding.Default)
lbwTemp.Write(sFileContent)

SaveFile = False

Note you can pass the file name directly to the constructor of
BinaryReader,
BinaryWriter, StreamReader & StreamWriter. You don't have to create a
FileStream first...
Hope this helps
Jay
"vvenk" <vv***@discussions.microsoft.com> wrote in message
news:4F**********************************@microsof t.com...
> Herfried:
>
> Thanks to you, I am able to read a binary file and store its contents
> into
> a
> string:
>
> Dim lfsTemp = New FileStream("Original.INI",
> IO.FileMode.Open)
> Dim lbrTemp = New BinaryReader(lfsTemp)
> Dim lbTemp = lbrTemp.ReadBytes(lbrTemp.BaseStream.Length)
> Dim sFileContent as String =
> System.Text.Encoding.Default.GetString(lbTemp)
>
> I tried saving sFileContent to a new file:
>
> Dim lfsTemp As New FileStream("Copy.Ini", FileMode.CreateNew)
> Dim lbwTemp As New BinaryWriter(lfsTemp)
>
> SaveFile = False
>
> lbwTemp.Write(sFileContent)
> lbwTemp.Close()
> lfsTemp.Close()
>
>
> I see that the two file sizes are not the same.
>
> Can you tell me why?
>
> Venkat
>


Nov 21 '05 #17

This discussion thread is closed

Replies have been disabled for this discussion.