:.RUN.:

lighting storm

将文件用base64编码保存成字符串,并从字符串中还原。

        //<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

        //  using System;

        //  using System.IO;

        //

 

        /// <summary>

        /// Temporary storage.

        /// </summary>

        private string buffer;

 

 

        /// <summary>

        /// Write base64 string to temp storage.

        /// </summary>

        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);

        }

 

        /// <summary>

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

        /// </summary>

        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();

        }

 

        /// <summary>

        /// Form event.

        /// </summary>

        /// <param name="sender"></param>

        /// <param name="e"></param>

        private void button1_Click(object sender, EventArgs e)

        {

            this.base64Encode("C://plastic.bmp");

        }

 

        /// <summary>

        /// Form event.

        /// </summary>

        /// <param name="sender"></param>

        /// <param name="e"></param>

        private void button2_Click(object sender, EventArgs e)

        {

            this.base64Decode("C://tmp.bmp");

        }

阅读更多
个人分类: .NET
想对作者说点什么? 我来说一句

ASP.NET之‘字符串’

-

学院

1970年01月01日 08:00

没有更多推荐了,返回首页

不良信息举报

将文件用base64编码保存成字符串,并从字符串中还原。

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭