zoukankan      html  css  js  c++  java
  • 将文件转换成byte[] 数组

    /// <summary>
    /// 将文件转换成byte[] 数组
    /// </summary>
    /// <param name="fileUrl">文件路径文件名称</param>
    /// <returns>byte[]</returns>
    protected byte[] GetFileData(string fileUrl)
    {
    FileStream fs = new FileStream(fileUrl, FileMode.Open, FileAccess.Read);
    try
    {
    byte[] buffur = new byte[fs.Length];
    fs.Read(buffur, 0, (int)fs.Length);

    return buffur;
    }
    catch (Exception ex)
    {
    //MessageBoxHelper.ShowPrompt(ex.Message);
    return null;
    }
    finally
    {
    if (fs != null)
    {

    //关闭资源
    fs.Close();
    }
    }
    }

    /// <summary>
    /// 将文件转换成byte[] 数组
    /// </summary>
    /// <param name="fileUrl">文件路径文件名称</param>
    /// <returns>byte[]</returns>

    protected byte[] AuthGetFileData(string fileUrl)
    {
    using (FileStream fs = new FileStream(fileUrl, FileMode.OpenOrCreate, FileAccess.ReadWrite))
    {
    byte[] buffur = new byte[fs.Length];
    using (BinaryWriter bw = new BinaryWriter(fs))
    {
    bw.Write(buffur);
    bw.Close();
    }
    return buffur;
    }
    }

  • 相关阅读:
    Problem 3
    Problem 2
    Problem 1
    Python基础 装饰器
    算法——狄克斯特拉算法
    A Knight's Journey POJ 2488
    多校10 1007 CRB and Queries
    多校9 1007 Travelling Salesman Problem
    多校8 1008 Clock
    多校7 1005 The shortest problem
  • 原文地址:https://www.cnblogs.com/ning-xiaowo/p/13572619.html
Copyright © 2011-2022 走看看