C# 文件分割和文件合并
C# 文件分割和文件合并
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | void SplitFile() { string sourceFile = "Old.mp4" ; // 源文件路径 string outputFile1 = "part1.bin" ; // 第一个输出文件路径(10KB) string outputFile2 = "part2.bin" ; // 第二个输出文件路径(剩余部分) int firstFileSize = 10 * 1024; // 第一个文件大小为 10KB(10 * 1024 字节) // 打开源文件 using (FileStream sourceStream = File.OpenRead(sourceFile)) { // 创建第一个输出文件 using (FileStream outputStream1 = File.Create(outputFile1)) { // 读取并写入第一个文件的 10KB 数据 byte [] buffer = new byte [firstFileSize]; int bytesRead = sourceStream.Read(buffer, 0, buffer.Length); outputStream1.Write(buffer, 0, bytesRead); } // 创建第二个输出文件 using (FileStream outputStream2 = File.Create(outputFile2)) { // 读取并写入剩余的数据 byte [] buffer = new byte [1024]; // 1KB 缓冲区 int bytesRead; while ((bytesRead = sourceStream.Read(buffer, 0, buffer.Length)) > 0) { outputStream2.Write(buffer, 0, bytesRead); } } } } void MergeFile() { string file1 = "part1.bin" ; // 第一个二进制文件路径 string file2 = "part2.bin" ; // 第二个二进制文件路径 string outputFile = "Merged.mp4" ; // 合并后的文件路径 // 打开输出文件流 using (FileStream outputStream = File.Create(outputFile)) { // 读取并写入第一个文件 using (FileStream inputStream = File.OpenRead(file1)) { inputStream.CopyTo(outputStream); // 将第一个文件内容复制到输出文件 } // 读取并写入第二个文件 using (FileStream inputStream = File.OpenRead(file2)) { inputStream.CopyTo(outputStream); // 将第二个文件内容复制到输出文件 } } } |
fffffffffffffffff
test red font.
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 字符编码:从基础到乱码解决
2019-01-14 WPF中ListBox /ListView如何改变选中条背景颜色
2019-01-14 c# C#获取屏幕鼠标坐标点颜色
2019-01-14 c# 无边框窗体的边框阴影