首页 > 代码库 > 对文件的读写操作

对文件的读写操作

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 =http://www.mamicode.com/ 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();        }    }}

 

对文件的读写操作