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