Hi,
How can you create a text file in C# and write to it? Sometimes you may need to create a text file using C sharp program. Here is how you can do that.
using System; using System.IO; class MainClass { static void Main(string[] args) { StreamWriter yourStream= null; string yourString= "I Love Coderz Heaven!"; try { yourStream = File.CreateText("testFile.txt"); yourStream.Write(yourString); } catch (IOException e) { Console.WriteLine(e); } catch (Exception e) { Console.WriteLine(e); } finally { if (yourStream!= null) { yourStream.Close(); } } } }
🙂
Useful blog website, keep me personally through searching it, I am seriously interested to find out another recommendation of it.
Beneficial info and excellent design you got here! I want to thank you for sharing your ideas and putting the time into the stuff you publish! Great work!
@daigoumee -> Glad to see your comment. Thank you so much. We will always try to keep it best.
@Maya Adduci -> Very glad to hear that comment. Comments like this will always keep us motivated. Thank you sooooo much. 🙂