在 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
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP