using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace WeiXin.Core
{
    public class FileToData
    {
        public string FileToBinary(string FilePath)
        {
            FileStream fs = new FileStream(FilePath,FileMode.Open,FileAccess.Read);
            int filelength = Convert.ToInt32(fs.Length);
            Byte[] filebyteArray = new byte[filelength];
            BinaryReader br = new BinaryReader(fs);
            for (int i = 0; i <filelength; i++)
            {
                br.Read(filebyteArray,0,filelength);
            }
            string strData = Convert.ToBase64String(filebyteArray);
            return strData;
        }

        public void BinaryToFile(string path,string Binary)
        {
            FileStream fs = new FileStream(path,FileMode.Create,FileAccess.Write);
            BinaryWriter bw = new BinaryWriter(fs);
            bw.Write(Convert.FromBase64String(Binary));
            bw.Close();
            fs.Close();
        }
    }
}