FileStream

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

    FileStream

    Hello!

    As far as I understand if I'm about to read all bytes from a file
    I must then first find out how many bytes this file consist of and
    then use the Read method on the FileStream object.

    So my question is if it's possible to read all bytes from
    a file without finding how many bytes this file consist of.

    //Tony


  • Jeroen Mostert

    #2
    Re: FileStream

    Tony Johansson wrote:
    As far as I understand if I'm about to read all bytes from a file
    I must then first find out how many bytes this file consist of and
    then use the Read method on the FileStream object.
    >
    Not at all, where did you get that idea?
    So my question is if it's possible to read all bytes from
    a file without finding how many bytes this file consist of.
    >
    Sure:

    byte[] b = File.ReadAllByt es("test.txt") ;

    --
    J.

    Comment

    • =?ISO-8859-1?Q?Arne_Vajh=F8j?=

      #3
      Re: FileStream

      Tony Johansson wrote:
      As far as I understand if I'm about to read all bytes from a file
      I must then first find out how many bytes this file consist of and
      then use the Read method on the FileStream object.
      >
      So my question is if it's possible to read all bytes from
      a file without finding how many bytes this file consist of.
      You read to EOF.

      EOF can be detected in various ways:
      - Stream read byte array returns 0 bytes read
      - Stream read single byte returns <0
      - StreamReader read line returns null
      etc.

      Arne

      Comment

      Working...