Save the file with the base64 encoding into strings and restore from the string.

zhaozj2021-02-16  120

//

// using system;

// using system.io;

//

///

/// Temporary Storage.

///

PRIVATE STRING BUFFER;

///

///Write base64 string to temp storage.

///

Private void base64encode (String fromfile)

{

FILESTREAM FileStream = file.open (fromFile, FileMode.Open);

Byte [] buffer = new byte [fileStream.length];

FileStream.read (buffer, 0, buffer.length);

FileStream.close ();

THIS.BUFFER = Convert.TOBASE64String (Buffer);

}

///

/// read base64 string from temp storage and save to file.

///

Private void base64decode (String Tofile)

{

FILESTREAM FILESTREAM = New FileStream (Tofile, FileMode.create);

Byte [] buffer = convert.frombase64string (this.buffer);

FileStream.write (buffer, 0, buffer.length);

FileStream.close ();

}

///

/// Form Event.

///

///

///

Private void button1_click (Object Sender, Eventargs E)

{

THIS.BASE64ENCODE ("C: //Plastic.bmp")

}

///

/// Form Event.

///

///

///

Private void button2_click (Object Sender, Eventargs E)

{

THIS.BASE64DECode ("C: //tmp.bmp");

}

转载请注明原文地址:https://www.9cbs.com/read-8554.html

New Post(0)