© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago
❓𝙋𝙮𝙩𝙖𝙟𝙣𝙞𝙠 🩷

Write to file not working (StreamWriter)

using System;
using System.Numerics;
using System.Text;
using System.IO;
namespace Username
{
    class Program
    {
        static void Main()
        {
            bool end = false;
            string filePath = @"C:\Users\Administrator\Desktop\HEXes.txt";

            StreamWriter hap = new(filePath, false, Encoding.Unicode);
            
            hap.WriteLine($"{F:N0} is {F:X}"); // there are variables I didn't mention, I just wanted to show here I write to file

            hap.Close();
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.Write("\nPress any key to continue...");
            Console.ReadKey();
        }
    }
}
using System;
using System.Numerics;
using System.Text;
using System.IO;
namespace Username
{
    class Program
    {
        static void Main()
        {
            bool end = false;
            string filePath = @"C:\Users\Administrator\Desktop\HEXes.txt";

            StreamWriter hap = new(filePath, false, Encoding.Unicode);
            
            hap.WriteLine($"{F:N0} is {F:X}"); // there are variables I didn't mention, I just wanted to show here I write to file

            hap.Close();
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.Write("\nPress any key to continue...");
            Console.ReadKey();
        }
    }
}
It creates HEXes.txt but the file is empty Never mind, my silly mistake. Closing.
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ StreamWriter not writing to file
C#CC# / help
11mo ago
✅ StreamWriter not writing to file
C#CC# / help
2y ago
❔ I Need help getting the Streamwriter object to write to a text file.
C#CC# / help
3y ago
✅ Serilog does not write logs to file
C#CC# / help
3y ago