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.IO;
- namespace User_name_with_text_stream
- {
- class Program
- {
- static void Main(string[] args)
- {
- string FILE_NAME = "user.txt"; // The file name.
- string Username; // A variable that stores the user name.
- string GetAction;
- if (File.Exists(FILE_NAME)) // Check: If the file exists.
- {
- TextReader read = new StreamReader(FILE_NAME);
- Username = read.ReadLine(); // Reading the username from the file.
- read.Close();
- Console.WriteLine("Hello " + Username);
- Console.Write("To change the username, please input 'Change'\nTo delete the data base, input 'Delete' or 'Erase' (Case Insensitive): ");
- GetAction = Console.ReadLine();
- if (GetAction == "Change" || GetAction == "change")
- {
- File.Delete(FILE_NAME);
- Console.Clear();
- Console.Write("Please enter your username: ");
- Username = Console.ReadLine();
- TextWriter write = new StreamWriter(FILE_NAME); // Creating the file.
- write.WriteLine(Username); // Writing to the file.
- write.Close();
- Console.Clear();
- Console.WriteLine("Account succesfully registered.\nYou may restart the program now.\n(Press 'Enter' to restart the program).");
- }
- else if (GetAction == "Delete" || GetAction == "delete" || GetAction == "Erase" || GetAction == "erase")
- {
- File.Delete(FILE_NAME);
- Console.WriteLine("Press 'Enter' to continue..");
- }
- Console.ReadKey();
- }
- else // If the file doesn't exist.
- {
- Console.Write("Please enter your username: ");
- Username = Console.ReadLine();
- TextWriter write = new StreamWriter(FILE_NAME); // Creating the file.
- write.WriteLine(Username); // Writing to the file.
- write.Close();
- Console.Clear();
- Console.WriteLine("Account succesfully registered.\nYou may restart the program now.\n(Press 'Enter' to restart the program).");
- Console.ReadKey();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement