C# 将文件转化成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, , (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;
}
}
C# 将文件转化成byte[]数组的更多相关文章
- 将文件转换成byte[]数组
代码 /// <summary> /// 将文件转换成byte[] 数组 /// </summary> /// <param name="fileUrl&quo ...
- JAVA将文件转换成byte数组(byte[])
/** * 将文件转换成byte数组 * @param filePath 文件File类 通过new File(文件路径) * @return byte数组 */ public static byte ...
- 将ImageList中的图片转化成byte数组
Image imgwd = this.imageList1.Images["wd.png"]; var bytes = ImageToBytes(imgwd); public by ...
- 获取文件数据流+叠加byte数组(给byte数组加包头包尾)
OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "(*.mp4)|*.mp4|(*.*)|*.*"; ofd.Res ...
- java 读取本地文件并转换为byte数组
private byte[] InputStream2ByteArray(String filePath) throws IOException { InputStream in = new File ...
- C# Byte[]数组读取和写入文件
这个项目我用的是asp.net构建的,代码如下 protected void ByteToString_Click(object sender, EventArgs e) { string conte ...
- JAVA中文件与Byte数组相互转换的方法
JAVA中文件与Byte数组相互转换的方法,如下: public class FileUtil { //将文件转换成Byte数组 public static byte[] getBytesByFile ...
- 将文件File转换成byte数组
代码如下: /** * 将文件转换成byte数组 * @param filePath * @return */ public static byte[] File2byte(File tradeFil ...
- JAVA获取文件byte数组并输出进行展示和文件下载
/** * 文件下载 */ @GetMapping(value = "/download") public void download(HttpServletResponse re ...
随机推荐
- Java WebClient 总结
private WebClient getAWebClient() { WebClient webClient = new WebClient(BrowserVersion.FIREFOX_24); ...
- Binary Tree Vertical Order Traversal
Given a binary tree, return the vertical order traversal of its nodes' values. (ie, from top to bott ...
- 【leetcode】Maximal Rectangle
Maximal Rectangle Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle conta ...
- ios oc 和 swfit 用dispatch_once 创建单例
网上已经有方法了,我这里就是抄了下,原文链接 http://bj007.blog.51cto.com/1701577/649413 http://blog.csdn.net/u010124617/ar ...
- lftp使用普通ftp模式登录
set ftp:use-feat no set ftp:passive-mode yes set ftp:ssl-protect-data no set ssl:verify-certificate ...
- c#缓存 笔记
1:缓存. 你需要了解大数据高并发的瓶颈在哪里,一般都是数据库层面的,机械硬盘承载不起非常快速的读写操作,cpu承载不起大量的逻辑运算,所以最基本的解决思路就是:1.换固态硬盘加快硬盘的读写效率.2. ...
- DataTemplate应用
在WPF中,决定数据外观的是DataTemplate,即DataTemplate是数据内容的表现形式,一条数据显示成什么样子,是简单的文本还是直观的图形,就是由DataTemplate决定的.下面通过 ...
- vs版本转换工具
[转]C#写的工程项目移植转换工具 – 支持VS2005/VS2010/VS2012/VS2013 经常用Visual Studio开发项目的是不是会经常遇到下面这种情况或者类似于这样的情况?用新 ...
- ajax 删除一条数据
代码: 对这一段话的理解:先找到需要删除的节点,以及节点里的文本:用Ajax 发送请求,请求方式为POST ,请求内容为需要删除记录的文件,dataType定义数据类型Json,通常都是Json,da ...
- mybatis一对多查询
18 <!-- 19 方式一:嵌套结果:使用嵌套结果映射来处理重复的联合结果的子集 20 封装联表查询的数据(去除重复的数据) 21 select * from class c, teacher ...