[英]VB6 TextStream in C#
What is alternative in c# for VB6 TextStream? c# 中 VB6 TextStream 的替代方法是什么?
Below Code-in VB6下面的代码在 VB6
ByRef strVarianceRpt As TextStream
How to write this in C#?如何用 C# 写这个? OR any other alternative in C#?
或 C# 中的任何其他替代方案?
The equivalent in C# would probably be a StreamReader
or StreamWriter
dependent upon whether you are reading or writing to a file. C# 中的等效项可能是
StreamReader
或StreamWriter
具体取决于您是在读取文件还是写入文件。
A StreamReader
:一个
StreamReader
:
Implements a TextReader that reads characters from a byte stream in a particular encoding.
实现一个 TextReader,它以特定的编码从字节流中读取字符。
Conversely, a StreamWriter
:相反,一个
StreamWriter
:
Implements a TextWriter for writing characters to a stream in a particular encoding.
实现一个 TextWriter,用于以特定编码将字符写入流。
Some examples of using them (taken from the MS Documentation) are:使用它们的一些示例(取自 MS 文档)是:
using (StreamReader sr = new StreamReader("TestFile.txt"))
{
string line;
while ((line = sr.ReadLine()) != null)
{
Console.WriteLine(line);
}
}
For the writer:对于作者:
DirectoryInfo[] cDirs = new DirectoryInfo(@"c:\").GetDirectories();
using (StreamWriter sw = new StreamWriter("CDriveDirs.txt"))
{
foreach (DirectoryInfo dir in cDirs)
{
sw.WriteLine(dir.Name);
}
}
Information can be found about StreamReader from the docs .可以从文档中找到有关 StreamReader 的信息。 The equivalent form StreamWriter are in the docs .
等效形式 StreamWriter 在文档中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.