distributed-computing/tasks/mikhailov-ys/lab_2/worker-1/Program.cs
2024-01-06 23:35:43 +04:00

38 lines
964 B
C#

using System;
using System.IO;
using System.Text;
string[] files = Directory.GetFiles("../var/data");
string maxFilePath = "";
long maxFileSize = 0;
foreach (var filePath in files)
{
FileInfo fileInfo = new FileInfo(filePath);
if (fileInfo.Length > maxFileSize)
{
maxFileSize = fileInfo.Length;
maxFilePath = filePath;
}
}
using (FileStream sourceStream = File.OpenRead(maxFilePath))
{
byte[] buffer = new byte[sourceStream.Length];
await sourceStream.ReadAsync(buffer, 0, buffer.Length);
string text = Encoding.Default.GetString(buffer);
using (FileStream targetStream = new FileStream("../var/result/data.txt", FileMode.OpenOrCreate))
{
targetStream.SetLength(0);
byte[] textBytes = Encoding.Default.GetBytes(text);
await targetStream.WriteAsync(textBytes, 0, textBytes.Length);
}
}
Console.WriteLine("Файл перемещен.");