forked from v.moiseev/distributed-computing
Готовый отчет/удалила ветвь1
This commit is contained in:
33
tasks/nikiforova-ts/Lab_2/worker-1/Program.cs
Normal file
33
tasks/nikiforova-ts/Lab_2/worker-1/Program.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
|
||||
string[] files = Directory.GetFiles("../../../../var/data");
|
||||
string minFilePath = "";
|
||||
long minFileNameLength = long.MaxValue;
|
||||
foreach (var filePath in files)
|
||||
{
|
||||
FileInfo fileInfo = new FileInfo(filePath);
|
||||
string fileName = Path.GetFileName(filePath);
|
||||
|
||||
if (fileName.Length < minFileNameLength)
|
||||
{
|
||||
minFileNameLength = fileName.Length;
|
||||
minFilePath = filePath;
|
||||
}
|
||||
}
|
||||
using (FileStream sourceStream = File.OpenRead(minFilePath))
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user