The initial solution of C # stream

Source: Internet
Author: User

PanPen120 on CSDN original, such as other sites reproduced please pay attention to the layout and the source:

Http://write.blog.csdn.net/postedit

How to understand, flow is a form of data loading, our pictures, music, videos, files, folders ... These are files, are data, and we use the cool dog, cool, QQ music and other players directly open a MP3 file to hear the sound, this is just mp3 this file a form of display, files we can use to display, store, read, transmit, through the form of streams. According to the principle of computer only know 0 and 1 ... No deep

The file is read as a stream in the form of a byte array:

Public byte[] LoadFile (string filePath)        {            try            {                FileStream stream = new FileStream (FilePath, FileMode.Open);                BinaryReader binary = new BinaryReader (stream);                Binary. Basestream.seek (0, seekorigin.begin);    Set the file pointer to file open                byte[] filebinary = binary. Readbytes ((int) binary. Basestream.length);                Stream. Close ();                return filebinary;            }            catch (Exception ex)            {                throw ex;            }                    }

To take the saved stream out:

public void SaveFile (String savepath, byte[] filebinary)        {            try            {                FileStream FileStream = new FileStream (Savepath, FileMode.OpenOrCreate);                FileStream. Write (filebinary, 0, filebinary.length);                FileStream. Close ();            }            catch (Exception ex)            {                throw ex;}}    }

I will be a desktop picture in the form of a stream saved in the database look: PanPen120 in csdn original, such as other sites reproduced please note the layout and the source:

Http://write.blog.csdn.net/postedit




The initial solution of C # stream

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.