filestream?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • cj

    #1

    filestream?

    VB2005

    I've opened files and read them using

    r = new io.streamreader ("c:\thisfile.t xt")
    line = r.readline

    Now I see an example where they are doing
    dim objopenfile as io.filestream = new io.filestream(f ilename,
    io.filemode.ope n, io.fileaccess.r ead, io.fileshare.re ad)
    dim objstreamreader as io.streamreader = new io.streamreader (objopenfile)
    textbox1.text=o bjstreamreader. readtoend()

    What is filestream and why would I want to use it?
  • Joseph Bittman MVP MCSD

    #2
    Re: filestream?

    Sept. 13, 2006

    Creating a new streamreader and providing a file name just creates a new
    stream to the file. If you create a filestream yourself and then pass it to
    the streamreader, you will get more options... like whether to only open the
    file for Reading, or only for Writing.

    At times, your user account may only have Read or Write NTFS privileges to a
    file... and opening a stream directly through a reader/writer may demand
    both privileges because it doesn't know what you will be doing.

    Just a matter of options... I don't think there's probably a performance
    difference.

    --

    Joseph Bittman
    Microsoft Certified Solution Developer
    Microsoft Most Valuable Professional -- DPM

    Blog/Web Site: http://CactiDevelopers.ResDev.Net/
    "cj" <cj@nospam.nosp amwrote in message
    news:%235887f31 GHA.968@TK2MSFT NGP03.phx.gbl.. .
    VB2005
    >
    I've opened files and read them using
    >
    r = new io.streamreader ("c:\thisfile.t xt")
    line = r.readline
    >
    Now I see an example where they are doing
    dim objopenfile as io.filestream = new io.filestream(f ilename,
    io.filemode.ope n, io.fileaccess.r ead, io.fileshare.re ad)
    dim objstreamreader as io.streamreader = new io.streamreader (objopenfile)
    textbox1.text=o bjstreamreader. readtoend()
    >
    What is filestream and why would I want to use it?

    Comment

    • cj

      #3
      Re: filestream?

      Thank you. I think I understand now.

      Joseph Bittman MVP MCSD wrote:
      Sept. 13, 2006
      >
      Creating a new streamreader and providing a file name just creates a
      new stream to the file. If you create a filestream yourself and then
      pass it to the streamreader, you will get more options... like whether
      to only open the file for Reading, or only for Writing.
      >
      At times, your user account may only have Read or Write NTFS privileges
      to a file... and opening a stream directly through a reader/writer may
      demand both privileges because it doesn't know what you will be doing.
      >
      Just a matter of options... I don't think there's probably a performance
      difference.
      >

      Comment

      Working...