Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6972557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:59:05+00:00 2026-05-27T16:59:05+00:00

I am attempting to write text out to a text file: byte[] b =

  • 0

I am attempting to write text out to a text file:

        byte[] b = new byte[100];
        int k = s.Receive(b);
        Console.WriteLine("Recieved...");
        for (int i = 0; i < k; i++)
        {
            Console.Write(Convert.ToChar(b[i]));
            //TextWriter tw = new StreamWriter("output.txt");
            //tw.WriteLine(Convert.ToChar(b[i]));

        }

Although the Console.Write method works perfectly, and text output is displayed on screen, but when I use the TextWriter method the application produces 100’s of errors (continues) and does not output anything to the output file specified

Is there any other way of getting the output of “Console.Write(Convert.ToChar(b[i]));” to a text file?

Below is a sample of the errors:

The server is running at port 8111… The local End point is
:172.16.0.37:8111 Waiting for a connection….. Connection accepted
from 172.16.0.37:59307 Recieved… //Error….. at
System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess
access, Int32 rights, Boolean useRights, FileShare share, Int32
bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String
msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String
path, FileMode mode, FileAccess access, FileShare share, Int32
bufferSize, FileOptions options) at
System.IO.StreamWriter.CreateFile(String path, Boolean append) at
System.IO.StreamWriter..ctor(String path, Boolean append, Encoding
encoding, Int32 bufferSize) at System.IO.StreamWriter..ctor(String
path) at IntegServer.Main() in
C:\Users\Limited\Desktop\IntegClient\IntegServer\IntegServer\Program.cs:line
38 Error….. at System.Net.Sockets.Socket.DoBind(EndPoint
endPointSnapshot, SocketAddress socketAddress) at
System.Net.Sockets.Socket.Bind(EndPoint localEP) at
System.Net.Sockets.TcpListener.Start(Int32 backlog) at
System.Net.Sockets.TcpListener.Start() at IntegServer.Main() in
C:\Users\Limited\Desktop\IntegClient\IntegServer\IntegServer\Program.cs:line
21 Error….. at System.Net.Sockets.Socket.DoBind(EndPoint
endPointSnapshot, SocketAddress socketAddress) at
System.Net.Sockets.Socket.Bind(EndPoint localEP) at
System.Net.Sockets.TcpListener.Start(Int32 backlog) at
System.Net.Sockets.TcpListener.Start() at IntegServer.Main() in
C:\Users\Limited\Desktop\IntegClient\IntegServer\IntegServer\Program.cs:line
21 Error….. at System.Net.Sockets.Socket.DoBind(EndPoint
endPointSnapshot, SocketAddress socketAddress) at
System.Net.Sockets.Socket.Bind(EndPoint localEP) at
System.Net.Sockets.TcpListener.Start(Int32 backlog) at
System.Net.Sockets.TcpListener.Start()

The full code follows:

  try
    {

        IPAddress ipAd = IPAddress.Parse("172.16.0.37"); //use local m/c IP address, and use the same in the client

        /* Initializes the Listener */
        TcpListener myList = new TcpListener(ipAd, 8111);

        /* Start Listeneting at the specified port */
        myList.Start();


            Console.WriteLine("The server is running at port 8111...");
            Console.WriteLine("The local End point is  :" + myList.LocalEndpoint);
            Console.WriteLine("Waiting for a connection.....");


        Socket s = myList.AcceptSocket();
        Console.WriteLine("Connection accepted from " + s.RemoteEndPoint);

        byte[] b = new byte[100];
        int k = s.Receive(b);
        Console.WriteLine("Recieved...");
        using (var txt = File.OpenWrite("output.txt"))
        {
            for (int i = 0; i < k; i++)
            {
                Console.Write(Convert.ToChar(b[i]));
                txt.WriteLine(Convert.ToChar(b[i]));
            }
        }




        ASCIIEncoding asen = new ASCIIEncoding();
        s.Send(asen.GetBytes("The string was recieved by the server."));
        Console.WriteLine("\nSent Acknowledgement to Client");
        /* clean up */
        s.Close();
        myList.Stop();


    }
    catch (Exception e)
    {
        Console.WriteLine("Error..... " + e.StackTrace);
    }
    // Loop the process
    loop();
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T16:59:06+00:00Added an answer on May 27, 2026 at 4:59 pm

    Maybe this is what you’re trying to do?

    byte[] b = new byte[100];
    int k = s.Receive(b);
    Console.WriteLine("Recieved...");
    using (var sw = new StreamWriter("output.txt"))
    {
        for (int i = 0; i < k; i++)
        {
            Console.Write(Convert.ToChar(b[i]));
            sw.Write(Convert.ToChar(b[i]));
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm attempting to write a text editor. I'm unable to open a file. Why?
I'm attempting to write a program that will generate a text file with every
I'm (attempting) to write a MySQL stored procedure that parses a large text file.
I'm attempting to write my own WYSWG text editor in Javascript, but I'm struggling
Im attempting to write a new component descendant from a common component (TDateTimePicker). My
I'm attempting to write a basic Tkinter GUI that has a Text widget at
I'm new to Treetop and attempting to write a CSS/HSS parser. HSS augments the
I've been attempting to write a Lisp macro that would perfom the equivalent of
I am attempting to write an application that uses libCurl to post soap requests
I'm attempting to write a Python C extension that reads packed binary data (it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.