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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:35:48+00:00 2026-06-09T20:35:48+00:00

My idea is to make my life a littler easier by encapsulating the StreamReader

  • 0

My idea is to make my life a littler easier by encapsulating the StreamReader and StreamWriter classes, the goal here is to have this class provide static methods that i can call to write and read from a file without having to instantiate objects of type StreamWriter/Reader and so on.

So far, I have the following code for my class:

Option Strict On

    Imports System.IO
    Imports System.IO.StreamReader 
    Imports System.IO.StreamWriter 



    Public Class ReadWrite
        Enum WriteType
            Append = 0
            WriteLine = 1
            Write = 2
        End Enum

        Enum ReadType
            Readline = 0
            Read = 1
        End Enum


        Shared Function Write (ByVal FilePath As String, ByVal _WriteType As WriteType, ByVal Content As String) As Boolean 

             Select Case _WriteType
                Case WriteType.Append
                    Using _append As StreamWriter = New StreamWriter(FilePath,True)
                        _append.WriteLine (Content)
                    End Using
                Case WriteType.Write 
                    Using _write As StreamWriter = New StreamWriter(FilePath, False)
                        _write.Write (Content)
                    End Using
                Case WriteType.WriteLine 
                      Using _writeline As StreamWriter = New StreamWriter(FilePath, False)
                        _writeline.Writeline (Content)
                    End Using
             End Select

            Return false
        End Function

         Shared Function Read (ByVal FilePath As String, ByVal _ReadType As ReadType) As Boolean 

             Select Case _ReadType
                Case ReadType.ReadLine
                Case ReadType.Read 
             End Select

            Return false
        End Function
    End Class

Question:
Is this a good method of accomplishing such task? What are some techniques i can use that will yield good results while maintaining code re-usability and simplicity; my goal is to make this flexible enough to use easily in other applications.

Thank you!

  • 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-09T20:35:50+00:00Added an answer on June 9, 2026 at 8:35 pm

    There is in general nothing wrong with writing little helper methods to make your life easier. But unfortunately you picked a Really Bad example.

    What goes wrong here is that you open and close a file for every single little bit of data you read or write to the file. Opening a file is an expensive operation, on most common hardware that costs around 50 milliseconds. And it is horribly prone to random failure, by closing a file you give another process the chance to open the file. Which may well lock you out, your next read/write can easily fail with an “access denied” exception. Impossible to debug since it is so random and caused by another process you can’t see.

    A simple workaround is to give the helper method an argument type of TextReader or TextWriter instead of string. Or by taking advantage of extension methods.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a idea to make table like this 1. something1 2. something2 3.
Is it a good or bad idea to make setters in java return this?
Idea: I want to make smth like real time electronic blackboard. Many users have
I recently had an idea to create my own String class to make using
So I got this crazy idea I could make make something cool work. I
Does WCF make your life easier or harder? Do you think it's beautiful in
I've been reading lots of questions at stackoverflow that have made my life easier,
I have this type of class hierarchy: public interface IA{} public interface IB{void Foo();}
Hi i'm trying to use jQuery/javascript to make my life easier. I'm trying to
I've created a PHP class that envelopes filter_input functions to make our developer's life

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.