67. Fayl nomini o'zgartirish uchun C# dasturini yozing.
Javob:
using System.IO;
File.Move("C:/myFolder/myFile.txt", "C:/myFolder/newName.txt");
68. Faylni nusxalash uchun C# dasturini yozing.
Javob:
using System.IO;
File.Copy("asli_fayl.txt", "nusxa_fayli.txt");
69. Faylni bir katalogdan boshqasiga o'tkazish uchun C# dasturini yozing.
Javob:
using System.IO;
string eski_katalog = @"C:\eski_katalog";
string yangi_katalog = @"D:\yangi_katalog";
Directory.Move(eski_katalog, yangi_katalog);
70. Faylni satr satr o'qish uchun C# dasturini yozing.
Javob:
using System.IO;
string fayl_nomi = "matnli_fayl.txt";
if (File.Exists(fayl_nomi))
{
using (StreamReader reader = new StreamReader(fayl_nomi))
{
string qator;
while ((qator = reader.ReadLine()) != null)
{
Console.WriteLine(qator);
}
}
}
else
{
Console.WriteLine("Fayl topilmadi");
}
71. Fayl mavjudligini tekshirish uchun C# dasturini yozing.
Javob:
using System.IO;
string fayl_nomi = "matnli_fayl.txt";
if (File.Exists(fayl_nomi))
{
Console.WriteLine("Fayl mavjud");
}
else
{
Console.WriteLine("Fayl topilmadi");
}
72. Fayl atributlarini olish uchun C# dasturini yozing.
Javob:
using System;
using System.IO;
class Program
{
static void Main()
{
FileInfo fileInfo = new FileInfo("example.txt");
Console.WriteLine("File attributes: " + fileInfo.Attributes);
}
}
73. Faylni yaratish vaqtini olish uchun C# dasturini yozing.
Javob:
using System;
using System.IO;
class Program
{
static void Main()
{
DateTime creationTime = File.GetCreationTime("example.txt");
Console.WriteLine("File created at: " + creationTime);
}
}
Do'stlaringiz bilan baham: |