distributed-computing/tasks/khalitova-am/lab_2/worker-1/Program.cs

23 lines
792 B
C#
Raw Permalink Normal View History

2023-10-03 23:36:51 +04:00
using System.Text;
2023-10-17 13:40:20 +04:00
string[] files = Directory.GetFiles("/var/data");
2023-10-03 23:36:51 +04:00
string maxFilePath = "";
long maxFileLenght = 0;
foreach(var filePath in files){
FileInfo fileInfo = new FileInfo(filePath);
if(fileInfo.Length > maxFileLenght){
maxFileLenght = fileInfo.Length;
maxFilePath = filePath;
}
}
using (FileStream fstream = File.OpenRead(maxFilePath)){
byte[] buffer = new byte[fstream.Length];
await fstream.ReadAsync(buffer, 0, buffer.Length);
string text = Encoding.Default.GetString(buffer);
2023-10-17 13:40:20 +04:00
using(FileStream fstream1 = new FileStream("/var/result/data.txt", FileMode.OpenOrCreate)){
2023-10-03 23:36:51 +04:00
fstream1.SetLength(0);
byte[] buffer1 = Encoding.Default.GetBytes(text);
await fstream1.WriteAsync(buffer1, 0, buffer1.Length);
}
}