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

  • Home
  • SEARCH
  • 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 9200789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:50:45+00:00 2026-06-17T22:50:45+00:00

I am trying to Make a Stream Writer and then write some input from

  • 0

I am trying to Make a Stream Writer and then write some input from the Console to a file and then Read the Content out. The only problem is I want to do it in two different methods. Write from here: addbook() and read from here: list_books(). But I can’t read from that file because the stream reader does not let me access any of my variables or that file to be used again.

//So I am trying to write from the static void addbook method and then read from the static void list_books method

//I want to Write from one static void and then I want  to read them from a different method.

static void addbook()
{
    //Here is where I get my strings that I will write

    Console.Write("Book Title:");
    string title = Console.ReadLine();

    Console.Write("ISBN#:");
    string isbn = Console.ReadLine();

    Console.Write("Author:");
    string author = Console.ReadLine();

    Console.Write("Publish Date:");
    string publish_date = Console.ReadLine();

    //Here Is where I create the Stream Reader and Writer
    //And where I write to the file
    var fs = File.Open("Librarybooks.txt", FileMode.OpenOrCreate,FileAccess.ReadWrite);
    var sw = new StreamWriter(fs);
    var sr = new StreamReader(fs);

    sw.WriteLine(title.ToCharArray());
    sw.WriteLine(isbn.ToCharArray());
    sw.WriteLine(author.ToCharArray());
    sw.WriteLine(publish_date.ToCharArray());

    Console.WriteLine("Book added Successfully!!");
}

static void list_books()
{
    //Here is where I want to read from so I can just call the list_books method.
    //But I can't access the StreamReader or StreamWriter
    //I just want to be able to read from the file.
}
  • 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-06-17T22:50:46+00:00Added an answer on June 17, 2026 at 10:50 pm
    private const string FILE_PATH = "Librarybooks.txt";
    
    static void addbook()
    {
        //Here is where I get my strings that I will write
    
        Console.Write("Book Title:");
        string title = Console.ReadLine();
    
        Console.Write("ISBN#:");
        string isbn = Console.ReadLine();
    
        Console.Write("Author:");
        string author = Console.ReadLine();
    
        Console.Write("Publish Date:");
        string publish_date = Console.ReadLine();
    
        //Here Is where I create the Stream Reader and Writer
        //And where I write to the file
        using (var fs = File.Open(FILE_PATH, FileMode.OpenOrCreate,FileAccess.ReadWrite))
        {
            using (var sw = new StreamWriter(fs))
            {
                using (var sr = new StreamReader(fs))
                {
                    sw.WriteLine(title.ToCharArray());
                    sw.WriteLine(isbn.ToCharArray());
                    sw.WriteLine(author.ToCharArray());
                    sw.WriteLine(publish_date.ToCharArray());
    
                    Console.WriteLine("Book added Successfully!!");
                 }
             }
         }
    }
    
    static void list_books()
    {
        using (StreamReader sr = new StreamReader(FILE_PATH))
        {
           string fileContent = sr.ReadToEnd();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently trying to read in an XML file, make some minor changes (alter
I'm trying to make a callback function, and then write the content retrieved into
I'm trying to write some STL data out of matlab and I'm trying to
So im trying to make an adroid application that draws a stream of circles
Trying to make the infamous checkall checkbox for dynamically created rows from a MySQL
I've been trying to write a class that derives from FramedSource in Live555 that
I'm trying to use C++11 features to make custom stream manipulators easier to create.
I'm trying to make a C# app that will connect to a file share,
I'm trying to make my Python script stream its output to my webpage as
I am trying to stream video from android camera through local unix socket and

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.