stream 文件操作
2024-08-31 20:36:38
简单的帮助类:
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;
}
最新文章
- 由乱序播放说开了去-数组的打乱算法Fisher–Yates Shuffle
- RSA不限长度非对称加密解密C#
- 如何设置unobtrusive的语言包
- Android 5.0 如何正确启用isLoggable(一)__使用详解
- Redis入门指南
- J2EE 第二阶段项目(八)
- [转载]java NIO详解
- GPT分区基础知识及如何在GPT分区上安装WIN7
- webpShere中数据库集群url的设置
- poj1222
- [js高手之路]深入浅出webpack教程系列6-插件使用之html-webpack-plugin配置(下)
- FCM算法的matlab程序2
- 轻量级浏览器Midori
- 一起来给iOS 11找bug: 苹果还是乔布斯时代的细节控吗?
- RedHat7安装vmware虚拟机启动报错
- C/C++-标准输入/输出重定向为文件输入/输出
- netcore如何引用package?
- 搞笑的<;Button>;<;/Button>;
- Sqli-labs less 7
- 第02章-装配Bean
热门文章
- 为何在查询中索引未被使用 (Doc ID 1549181.1)
- Opencv距离变换distanceTransform应用——细化字符轮廓&&查找物体质心
- Kinect 骨骼映射---Let me dance for U!
- [Node.js] Use nodejs-dashboard event loop delay with hrtime()
- 高性能 Python —— vectorization
- auto_create_partition
- [tmux] Organize your terminal using tmux panes
- 【a501】算24点
- Sitecore
- 【b604】2K进制数