简单的帮助类:

        private static byte[] StreamToBytes(Stream fs)
{
byte[] bArr = new byte[fs.Length];
fs.Read(bArr, , (int)fs.Length);
fs.Seek(, SeekOrigin.Begin);
return bArr;
} public static Stream BytesToStream(byte[] bytes)
{
Stream stream = new MemoryStream(bytes);
return stream;
} public static byte[] FileToBytes(string path)
{
using (FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read))
{
byte[] bArr = new byte[fileStream.Length];
fileStream.Read(bArr, , bArr.Length);
return bArr;
}
} public static string BytesToFile(string directoryPath,byte[] bArr,string fileName)
{
if (!Directory.Exists(directoryPath))
{
Directory.CreateDirectory(directoryPath);
}
string path = directoryPath + "\\" + fileName;
using (FileStream fileStream = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write))
{
fileStream.Seek(, SeekOrigin.Begin);
fileStream.Write(bArr, , bArr.Length);
}
return path;
}

stream 文件操作的更多相关文章

  1. 14、Java文件操作stream、File、IO

    1.文件操作涉及到的基本概念 File File类 是文件操作的主要对象中文意义就是 文件 顾名思意 万物皆文件,在计算上看到的所有东西都是文件保存,不管是你的图片.视频.数据库数据等等都是按照基本的 ...

  2. Node基础篇(文件操作)

    文件操作 相关模块 Node内核提供了很多与文件操作相关的模块,每个模块都提供了一些最基本的操作API,在NPM中也有社区提供的功能包 fs: 基础的文件操作 API path: 提供和路径相关的操作 ...

  3. 前端学PHP之文件操作

    × 目录 [1]文件类型 [2]文件属性 [3]目录路径[4]目录遍历[5]目录统计[6]目录增删[7]目录复制[8]文件操作[9]文件内容 前面的话 在程序运行时,程序本身和数据一般都存在内存中,当 ...

  4. Web API与文件操作

    前段时间,一直有练习ASP.NET MVC与Web API交互,接下来,Insus.NET再做一些相关的练习,Web API与文件操作,如POST文件至Web API,更新或是删除等. 不管怎样,先在 ...

  5. Python开发【第三篇】:Python基本之文件操作

    Python基本之文本操作 一.初识文本的基本操作 在python中打开文件有两种方式,即:open(...) 和  file(...) ,本质上前者在内部会调用后者来进行文件操作,推荐使用 open ...

  6. Linux C 文件操作,系统调用 -- open()、read() 和 标准I/O库 -- fopen()、fread()

    函数汇总: open().write().read().close() fopen().fwrite().fread().fclose() 一.什么是文件 在讲述文件操作之前,我们首先要知道什么是文件 ...

  7. C# 文件操作笔记

    C#中的文件操作 文件操作中的常见类: 静态类 File类:提供很多静态方法,用于移动.复制和删除文件. Directory类:用于移动.复制和删除目录. Path类:用于处理与路径相关的操作. 实例 ...

  8. C的文件操作2

    [转] C语言文件操作  概述 所谓文件(file)一般指存储在外部介质上数据的集合,比如我们经常使用的mp3.mp4.txt.bmp.jpg.exe.rmvb等等.这些文件各有各的用途,我们通常将它 ...

  9. PHP的文件操作常用函数

    PHP文件操作 1 获得文件名:basename - 返回路径中的文件名部分 给出一个包含有指向一个文件的全路径的字符串,本函数返回基本的文件名.如果文件名是以 suffix 结束的,那这一部分也会被 ...

随机推荐

  1. matplotlib学习之函数积分图

    # coding:utf-8 import numpy as np from matplotlib import pyplot as plt from matplotlib.patches impor ...

  2. Linux系统下的单调时间函数

    欢迎转载,转载请注明出处:http://forever.blog.chinaunix.net 一.编写linux下应用程序的时候,有时候会用到高精度相对时间的概念,比如间隔100ms.那么应该使用哪个 ...

  3. Android 控件EditText的setOnEditorActionListener方法的理解

    需要注意的是 setOnEditorActionListener这个方法,并不是在我们点击EditText的时候触发,也不是在我们对EditText进行编辑时触发,而是在我们编辑完之后点击软键盘上的回 ...

  4. Android 自定义RadioButton样式

     上面这种3选1的效果如何做呢?用代码写? 其实有更简单的办法,忘了RadioButton有什么特性了吗? 我就用RadioButton实现了如上效果,其实很简单的. 首先定义一张background ...

  5. SpringMVC接受参数若干问题

    最近2年在工作问题总结中,好几次遇到了SpringMVC接收参数的问题,今天特别总结下.  SpringMVC接收参数的方法:  Html参数输入: <input name="stat ...

  6. 基于 MySQL 5.6 keepalived的双主搭建

    环境介绍: 说明 IP 节点1 192.168.56.56 节点2 192.168.56.57 w_ip 192.168.56.6 安装keepalived tar -zxvf keepalived- ...

  7. (转自aierong原创技术随笔)sqlserver字符串拆分(split)方法汇总

    sqlserver字符串拆分(split)方法汇总   --方法0:动态SQL法declare @s varchar(100),@sql varchar(1000)set @s='1,2,3,4,5, ...

  8. 【codeforces 546D】Soldier and Number Game

    time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  9. C++ 快速入门笔记:面向对象编程

    类 & 对象 类定义 class Box { public: double length; // Length of a box double breadth; // Breadth of a ...

  10. [Angular] Dynamic component's instance and sorting

    After create a component dynamic, we are able to change the component's props and listen to its even ...