Harry Potter and the Sorcerer's Stone


Faylning oxirgi kirish vaqtini olish uchun C# dasturini yozing


Download 192.49 Kb.
bet53/62
Sana17.06.2023
Hajmi192.49 Kb.
#1535967
1   ...   49   50   51   52   53   54   55   56   ...   62
Bog'liq
Algaritim amaliy-2

74. Faylning oxirgi kirish vaqtini olish uchun C# dasturini yozing.
Javob:
using System;
using System.IO;
class Program
{
static void Main()
{
DateTime lastAccessTime = File.GetLastAccessTime("example.txt");
Console.WriteLine("File last accessed at: " + lastAccessTime);
}
}
75. Faylning oxirgi yozish vaqtini olish uchun C# dasturini yozing.
Javob:
using System;
using System.IO;
class Program
{
static void Main()
{
DateTime lastWriteTime = File.GetLastWriteTime("example.txt");
Console.WriteLine("File last written at: " + lastWriteTime);
}
}
76. Belgilangan o'lchamdagi yangi fayl yaratish uchun C# dasturini yozing.
Javob:
using System;
using System.IO;
class Program
{
static void Main()
{
string fileName = "newfile.txt";
int fileSize = 1024; // 1KB

using (FileStream fs = new FileStream(fileName, FileMode.CreateNew))


{
fs.SetLength(fileSize);
Console.WriteLine("New file created: " + fileName + ", size: " + fileSize + " bytes");
}
}
}
77. Faylning zaxira nusxasini yaratish uchun C# dasturini yozing.
Javob:
string sourceFile = "C:\\example\\source.txt";
string destinationFile = "C:\\example\\destination.txt";
File.Copy(sourceFile, destinationFile);
78. Faylni siqish uchun C# dasturini yozing.
Javob:
string filePath = "C:\\example\\file.txt";
FileInfo file = new FileInfo(filePath);
file.IsReadOnly = true;
79. Faylni shifrlash uchun C# dasturini yozing.
Javob:
string filePath = "C:\\example\\file.txt";
string password = "secretPassword";
byte[] salt = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
Rfc2898DeriveBytes keyGenerator = new Rfc2898DeriveBytes(password, salt);
byte[] key = keyGenerator.GetBytes(32);
byte[] iv = keyGenerator.GetBytes(16);
using (FileStream inputFileStream = new FileStream(filePath, FileMode.Open))
{
using (FileStream outputFileStream = new FileStream(filePath + ".encrypted", FileMode.Create))
{
using (Aes aesEncryptor = Aes.Create())
{
aesEncryptor.KeySize = 256;
aesEncryptor.BlockSize = 128;
aesEncryptor.Key = key;
aesEncryptor.IV = iv;

using (CryptoStream cryptoStream = new CryptoStream(outputFileStream, aesEncryptor.CreateEncryptor(), CryptoStreamMode.Write))


{
inputFileStream.CopyTo(cryptoStream);
}
}
}
}

Download 192.49 Kb.

Do'stlaringiz bilan baham:
1   ...   49   50   51   52   53   54   55   56   ...   62




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling