我在拆分文件时遇到一些问题,我现在不知道该怎么办。我必须拆分电影,然后将拆分的元素合并为一个。我必须使用FileStream。如果你能帮助我,我将非常高兴:)
using System;
using System.Collections.Generic;
using System.IO;
class Program
{
static void Main()
{
string source = "../../movie.avi";
string destination;
int n = int.Parse(Console.ReadLine());
for (int i = 0; i < n; i++)
{
destination = "Part-" + i +".avi";
Slice(source, destination, n);
}
List<int> files = new List<int>();
//Assemble(, destination);
}
static void Slice(string sourceFile, string destinationDirectory, int parts)
{
using (var source = new FileStream(sourceFile, FileMode.Open))
{
for (int i = 0; i < parts; i++)
{
using (var destination = new FileStream(destinationDirectory, FileMode.CreateNew))
{
double fileLength = source.Length;
byte[] buffer = new byte[4096];
while (true)
{
int readBytes = source.Read(buffer, 0, buffer.Length);
if (readBytes == 0)
{
break;
}
destination.Write(buffer, 0, readBytes);
}
}
}
}
}
static void Assemble(List<string> files, string destinationDirectory)
{
}
}