Mutual transformation of files and streams

Source: Internet
Author: User

1  Public classUploadFile2 {3     //file name4      Public stringfilename{Get;Set;}5     //File Type6      PublicStorageFile file{Get;Set;}7     8     //File Data Flow9     PublicStream FileStream {Get;Private Set; }Ten     One     A      Publicuploadfile (StorageFile file) -     { -          This. storagefile=file. Name; the          This. file=file; -     } -      -     //convert files to streams +      Public Asynctask<byte[]>GetBytes () -     { +FileStream = (Stream)awaitFile.openstreamforreadasync (); A         byte[] bytes =New byte[filestream.length]; atFileStream.Read (Bytes,0, Bytes. Length); -Filestream.seek (0, seekorigin.begin); -         returnbytes; -     } -      -      in      -     //write a stream to a file to         Public Async voidGetFile (byte[] bytes) +         {  -Storagefolder Applicationfolder =ApplicationData.Current.LocalFolder; theStorageFile StorageFile =awaitApplicationfolder.createfileasync ("1.txt", creationcollisionoption.replaceexisting); *StorageFile file =awaitApplicationfolder.getfileasync ("1.txt"); $             using(varstream =awaitfile. Openstreamforwriteasync ())Panax Notoginseng             { -                 awaitStream. WriteAsync (Bytes,0, Bytes. Length); the Stream. Flush (); +             } A  the      +}

Mutual transformation of files and streams

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.