distributed-computing/tasks/kazakov-ev/lab_2/worker-1/Program.cs

24 lines
788 B
C#
Raw Normal View History

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