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