0

我在 vb6 中有以下代码 -

dim iFreeFile as integer

iFreeFile = FreeFile
Open tSendFileName For Output As #iFreeFile

我需要将其转换为 C#,但我遇到了困难。我试图使用 StreamWriter 但遇到了不知道在哪里写入或如何插入文件的问题,因为它不在我的计算机上。

关于如何将此代码转换为 C# 的任何想法?谢谢

4

2 回答 2

3

使用 streamwriter 写入文本文件非常简单:

using (StreamWriter sw = new StreamWriter(tSendFileName)) {
    sw.WriteLine("Some text"); //write text followed by line terminator
    sw.Write("Foo...bar...foo...bar"); //write text without terminator
}
于 2012-06-26T22:41:20.603 回答
0
MemoryStream ms = new MemoryStream(); 
TextWriter tw = new StreamWriter(ms);


tw.WriteLine("Creating file in memory.");
tw.WriteLine("Adding extra line.");

// just use savedialog to save file on disk
File.WriteAllBytes(SaveFileDialog1.FileName, ms.GetBuffer());
于 2012-06-26T18:26:17.697 回答