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 995229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:41:27+00:00 2026-05-16T06:41:27+00:00

See the program below: using System; using System.Collections.Generic; using System.Text; using System.IO; namespace FileOperation1

  • 0

See the program below:

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace FileOperation1
{
    class FileMain
    {
        static void Main(string[] args)
        {
            FileMain fm = new FileMain();
            char ch = fm.Menu();
            while (ch != '0')
            {
                switch (ch)
                { 
                    case '0':
                        break;
                    case '1':
                        //Console.WriteLine("This featute is not implemented till now.");
                        break;
                    case '2':
                        Console.Write("Enter the name of the file: ");
                        String FileName = Console.ReadLine();// ReadLine() method is not workin here
                        FileOperation Fo=new FileOperation();
                        Console.WriteLine("\n" + Fo.FileRead(FileName, FileMode.Open, FileAccess.Read));
                        break;
                    case '3':
                        //Console.WriteLine("This featute is not implemented till now.");
                        break;
                    default:
                        Console.WriteLine("Invalid choice. Enter again.");
                        break;
                }
                ch = fm.Menu();
            }
        }
        private char Menu()
        {
            Console.WriteLine("\n\t***File Operations***");
            Console.WriteLine("1. Create a new file");
            Console.WriteLine("2. Open a file");
            Console.WriteLine("3. Edit an existing file");
            Console.WriteLine("0. Exit");
            Console.Write("\nEnter your choice: "); 
            char ch = Convert.ToChar(Console.Read()); //Read() Method is not working properly
            return ch;
        }
    }
    public class FileOperation
    {
        private String FileRead(FileStream Fs)
        {
            StreamReader Sr = new StreamReader(Fs);
            Sr.BaseStream.Seek(0, SeekOrigin.Begin);
            String str = ""+(Char)Sr.Read();
            String ret = "";
            while (!Sr.EndOfStream)
            {
                ret += str;
                str = ""+(Char)Sr.Read();
            }
            Sr.Close();
            return ret;
        }
        public String FileRead(String FileName, FileMode Fm, FileAccess Fa)
        {
            FileOperation Fo = new FileOperation();
            FileStream Fs = new FileStream(FileName, Fm, Fa);
            String ret = Fo.FileRead(Fs);
            Fs.Close();
            return ret;
        }
    }
}

I am using Visual Studio 2005. Here Console.ReadLine() and Console.Read() functions are not working properly for this program. Why?

  • 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-16T06:41:28+00:00Added an answer on May 16, 2026 at 6:41 am

    Replace Console.Read() methods with Console.ReadLine(). See more about Console.Read() and Console.ReadLine() method from MSDN. Edited program is given below:

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.IO;
    
    namespace FileOperation1
    {
        class FileMain
        {
            static void Main(string[] args)
            {
                FileMain fm = new FileMain();
                char ch = fm.Menu();
                while (ch != '0')
                {
                    switch (ch)
                    {
                        case '0':
                            break;
                        case '1':
                            //Console.WriteLine("This featute is not implemented till now.");
                            break;
                        case '2':
                            Console.Write("Enter the name of the file: ");
                            String FileName = Console.ReadLine();// ReadLine() method is not workin here
                            FileOperation Fo = new FileOperation();
                            Console.WriteLine("\n" + Fo.FileRead(FileName, FileMode.Open, FileAccess.Read));
                            break;
                        case '3':
                            //Console.WriteLine("This featute is not implemented till now.");
                            break;
                        default:
                            Console.WriteLine("Invalid choice. Enter again.");
                            break;
                    }
                    ch = fm.Menu();
                }
            }
            private char Menu()
            {
                Console.WriteLine("\n\t***File Operations***");
                Console.WriteLine("1. Create a new file");
                Console.WriteLine("2. Open a file");
                Console.WriteLine("3. Edit an existing file");
                Console.WriteLine("0. Exit");
                Console.Write("\nEnter your choice: ");
                char ch = Convert.ToChar(Console.ReadLine()); //Read() Method is not working properly
                return ch;
            }
        }
        public class FileOperation
        {
            private String FileRead(FileStream Fs)
            {
                StreamReader Sr = new StreamReader(Fs);
                Sr.BaseStream.Seek(0, SeekOrigin.Begin);
                String str = "" + (Char)Sr.Read();
                String ret = "";
                while (!Sr.EndOfStream)
                {
                    ret += str;
                    str = "" + (Char)Sr.Read();
                }
                Sr.Close();
                return ret;
            }
            public String FileRead(String FileName, FileMode Fm, FileAccess Fa)
            {
                FileOperation Fo = new FileOperation();
                FileStream Fs = new FileStream(FileName, Fm, Fa);
                String ret = Fo.FileRead(Fs);
                Fs.Close();
                return ret;
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

See below code first please. using System; using System.Collections.Generic; namespace ConsoleApplication1 { class Program
I see a program to reverse a string public class ReverseName{ public static void
Consider the following C# program: using System; using System.Diagnostics; namespace Test { class MainClass
As you can see below, I have Parallel.For loop. If run the program while
I am using c# for programming, please see below code: <p><b> <%=ResourceFile.GetResourceString(c_FreeLiveOnlineProgramInterest)%> </b>&nbsp;<font color=red>*</font>&nbsp;
struct mydata { public int id; public string data; } class Program { static
I would like to see how a program responds when it's connection is severed.
I need my program to see different colors. Pretty much all I need is
In the following program you can see that each value slightly less than .5
I wrote a simple test program for opencv to see if it's working after

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.