Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. convert large files into byte []

convert large files into byte []

Scheduled Pinned Locked Moved C#
question
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    abbd
    wrote on last edited by
    #1

    Hello, how can i convert the large files that exceed 2GB in the binary table, I use byte [] data = File.ReadAllBytes (path); and i have exception. There are another way? thank you very much.

    J OriginalGriffO 2 Replies Last reply
    0
    • A abbd

      Hello, how can i convert the large files that exceed 2GB in the binary table, I use byte [] data = File.ReadAllBytes (path); and i have exception. There are another way? thank you very much.

      J Offline
      J Offline
      jschell
      wrote on last edited by
      #2

      Stream it rather than attempting to read it all at one time.

      1 Reply Last reply
      0
      • A abbd

        Hello, how can i convert the large files that exceed 2GB in the binary table, I use byte [] data = File.ReadAllBytes (path); and i have exception. There are another way? thank you very much.

        OriginalGriffO Offline
        OriginalGriffO Offline
        OriginalGriff
        wrote on last edited by
        #3

        As previously stated, streaming is probably the only way, unless you want to manually read chunks of the file. .NET has a limit on the maximum size of any one object of 2GB - so no string or array of bytes can exceed this. If you want to read a file bigger than this limit, you have to work in chunks, you cannot read it into any single object in it's entirety. It should be possible to declare an array like type that provides this chunking, and hides the stream or whatever from the main code. In fact there is an example of this on MSDN: http://msdn.microsoft.com/en-us/library/aa288465(v=vs.71).aspx[^] although their method does seem somewhat inefficient, and I would probably cache a block of data if I did it. Depends on how random-access your data is! [edit]Typo: "there" for "their" - OriginalGriff[/edit]

        Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
        "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups