Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.IO;
- namespace WriteFile
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.OutputEncoding = Encoding.Unicode;
- Console.InputEncoding = Encoding.Unicode;
- string filePath = "test.txt";
- FileStream fsR = new FileStream(filePath, FileMode.Open);
- StreamReader sReader = new StreamReader(fsR, Encoding.Unicode);
- string firstValue = sReader.ReadLine();
- string[] value = firstValue.Split(':');
- sReader.Close();
- Console.Write("Username : ");
- string username = Console.ReadLine();
- Console.Write("Password : ");
- string password = Console.ReadLine();
- if (value[0] == username && value[1] == password)
- {
- Console.WriteLine($"Xin chào {value[2]}, chức vụ hiện tại của bạn là {value[3]}");
- Console.WriteLine("----------Menu----------");
- Console.WriteLine("1: Cập nhập username");
- Console.WriteLine("2: Cập nhập pass");
- Console.WriteLine("3: Cập nhập họ tên");
- Console.WriteLine("4: Cập nhập chức vụ");
- Console.WriteLine("-------------------------");
- Console.WriteLine("Mời bạn chọn lựa chọn");
- int option = int.Parse(Console.ReadLine());
- switch (option)
- {
- case 1:
- {
- Console.Write("Nhập username : ");
- value[0] = Console.ReadLine();
- break;
- }
- case 2:
- {
- Console.Write("Nhập password : ");
- value[1] = Console.ReadLine();
- break;
- }
- case 3:
- {
- Console.Write("Nhập họ tên : ");
- value[2] = Console.ReadLine();
- break;
- }
- case 4:
- {
- Console.Write("Nhập chức vụ : ");
- value[3] = Console.ReadLine();
- break;
- }
- }
- writeFile($"{value[0]}:{value[1]}:{value[2]}:{value[3]}");
- Console.WriteLine("Cập nhập thành công !");
- }
- else Console.WriteLine("Sai tài khoảng hoặc mật khẩu rùi bận êyyyy !");
- }
- static void writeFile(string data)
- {
- string filePath = "test.txt";
- FileStream fsW = new FileStream(filePath, FileMode.Create);
- StreamWriter sWriter = new StreamWriter(fsW, Encoding.Unicode);
- sWriter.Write(data);
- sWriter.Flush();
- fsW.Close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement