C#中的StreamWriter
使用C#中的StreamWriter将字符写入流中。
使用StreamWriter,创建一个新文件-
StreamWriter sw = new StreamWriter("hello.txt"))将文本添加到文件-
sw.WriteLine("Hello");
sw.WriteLine("World");以下是代码-
示例
using System.IO;
public class Program {
public static void Main() {
using (StreamWriter sw = new StreamWriter("hello.txt")) {
sw.WriteLine("Hello");
sw.WriteLine("World");
}
}
}它创建文件“hello.text”并向其中添加文本-
输出结果
以下是输出。
Hello World
热门推荐
10 对疫情的简短祝福语
11 祝妹妹毕业祝福语简短
12 好听的元旦简短祝福语
13 团队文案祝福语简短励志
14 农民朋友发财祝福语简短
15 中秋祝福语送朋友简短
16 生病祝福语简短文案
17 生女儿的祝福语简短
18 新年祝福语简短给孩子