Results 1 to 6 of 6

Thread: [RESOLVED] [2.0] FileStream object why ???

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2003
    Posts
    436

    Resolved [RESOLVED] [2.0] FileStream object why ???

    In order to read and write to a sequential file, I am using Streamreader and streamwriter classes. and it works fine.

    In a book which I am going thru, first a "FileStream" object is created.

    why do I need a "FileStream" object?

    thanks
    nath

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2003
    Posts
    436

    Unhappy Re: [2.0] FileStream object why ???

    I meant for example:

    FileStream stmWeekdays = new FileStream("Weekdays.txt", FileMode.Create, FileAccess.Write, FileShare.None);

    StreamWriter stmWriter = new StreamWriter(stmWeekdays);

    why can't I pass the path name of the file while creating stmWriter object.
    I don't understand the benefit of using FileStream object.

    thanks
    nath

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2.0] FileStream object why ???

    You can pass the name of the file. The thing is, you need a FileStream regardless. If you pass the name of the the file to the StreamReader or StreamWriter constructor then it simply creates the FileStream for you. A reference to that FileStream can then be retrieved through the BaseStream property.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2003
    Posts
    436

    Re: [2.0] FileStream object why ???

    Hello jm,

    could you give me an example with brief explanation ?

    thank you so much
    nath

  5. #5
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: [2.0] FileStream object why ???

    Books don't specify the best way to do things (Not so often)
    They aim to using as much classes as possible so you learn their usability
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2.0] FileStream object why ???

    If you want an example then go to the MSDN library. The topic for each StreamWriter constructor has the same code example that shows how to use each of them. MSDN should always be your first stop.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width