FileGet和StreamReader之间的差异 [英] Discrepancies between FileGet and StreamReader

查看:85
本文介绍了FileGet和StreamReader之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好:


当我使用任何一个读取文本文件时,我得到相同的结果。文件内容写入的字符串的长度

是相同的。


但是,如果文件是二进制文件,则FileGet获取我是正确的内容而

StreamReader给了我一个截断的字符串。


有人可以告诉我为什么吗?我应该使用BinaryReader代替

StreamReader吗? BinaryReader会处理文本文件吗?


Venkat

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

推荐答案

我尝试使用BinayReader但不像简单的单一的

声明如下:


FileGet(ciFileHandle,sFileContent)


将读取内容将文件放入sFileContent,我必须一次读取一个字节的
并连接到sFileContent。


是否有一个Stream / Binary类可以工作在文本和二进制文件上?
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?


" vvenk" < VV *** @ discussions.microsoft.com> schrieb:
"vvenk" <vv***@discussions.microsoft.com> schrieb:
有人可以告诉我为什么吗?我应该使用
BinaryReader而不是StreamReader吗?


取决于你想做什么。请注意,你可以在'$ $ $ b'中指定''StreamReader''的构造函数。

BinaryReader会处理文本文件吗?
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?




是的。


\\\

Dim br As New System.IO.BinaryReader(_

新的System.IO.FileStream(" C:\ foo.txt",IO.FileMode.Open)_



Dim abyt( )By 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/>



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/>


Herfried:


谢谢你非常喜欢你的小费。在我看来,BinaryReader更具有多种功能,因为它可以处理不同的编码。


Venkat


Herfried K. Wagner [MVP]"写道:
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:
"vvenk" <vv***@discussions.microsoft.com> schrieb:
有人可以告诉我为什么吗?我应该使用
BinaryReader而不是StreamReader吗?
Can somebody advise me why? Should I be using
BinaryReader instead of StreamReader?



取决于你想做什么。请注意,您可以在''StreamReader'的构造函数中指定编码。



Depends on what you want to do. Notice that you can specify an encoding in
the ''StreamReader''''s constructor.

BinaryReader会处理文本文件吗?
Would BinaryReader work on text files?



是的。

\\\
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/>



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/>



这篇关于FileGet和StreamReader之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆