将文件转换为二进制流/二进制串

来源:互联网 发布:手机源码怎么用 编辑:程序博客网 时间:2024/05/14 01:36

    /// <summary>
    /// 将文件转换为二进制串
    /// </summary>
    /// <param name="filePath">文件的路径</param> 
    /// <returns></returns>
    public byte[] FileToBytes(string filePath)
    {
        FileInfo fi = new FileInfo(filePath);
        FileStream fs = fi.OpenRead();
        byte[] bytes = new byte[fs.Length];
        fs.Read(bytes, 0, Convert.ToInt32(fs.Length));
        fs.Close();
        return bytes;
    }