Консольный текстовый редактор с возможностью создания и сохранения файлов - C#
Формулировка задачи:
Люди помогите пожалуйста у меня завтра зачет по программированию на си шарп. Дали задание: "Создать Консольный текстовый редактор с возможностью создания и сохранения файлов". Код начал писать два дня назад и никак не закончу. Помогите его закончить.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace текстовой_редактор_в_консоли
{
class Program
{
static void Main(string[] args)
{
verh:
Console.BackgroundColor = ConsoleColor.DarkBlue;
Console.Clear();
Console.BackgroundColor = ConsoleColor.Yellow;
Console.MoveBufferArea(0, 0, 80, 20, 0, 4);
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("Введите имя файла");
Console.ForegroundColor = ConsoleColor.White;
string FileImya = Console.ReadLine();
if (string.IsNullOrEmpty(FileImya))
{
Console.WriteLine("Не заданно имя файла");
if (Console.ReadKey().Key == ConsoleKey.Escape) return;
else { Console.Clear(); goto verh; }
}
Console.BackgroundColor = ConsoleColor.White;
Console.ForegroundColor = ConsoleColor.Yellow;
Console.Clear();
Console.BackgroundColor = ConsoleColor.Green;
Console.MoveBufferArea(0, 0, 80, 20, 0, 4);
Console.ForegroundColor = ConsoleColor.Blue;
Console.Write("Файл" + FileImya);
// SetHelpString();
Console.SetCursorPosition(0, 5);
Console.BackgroundColor = ConsoleColor.Blue;
Console.ForegroundColor = ConsoleColor.Yellow;
if (File.Exists(FileImya))
{
using (StreamReader reader = new StreamReader(FileImya, Encoding.Default))
{
Console.Write(reader.ReadToEnd());
}
}
using (StreamWriter writer = new StreamWriter(FileImya, true, Encoding.Default))
{
}
}
}
}Решение задачи: «Консольный текстовый редактор с возможностью создания и сохранения файлов»
textual
Листинг программы
class Program
{
static void Main(string[] args)
{
bool fl = true;
do
{
Console.WriteLine("*********** Menu ***********");
Console.WriteLine("Создать файл для записи текста -> 1\nОткрыть созданнный файл для чтения -> 2\nВыход -> 3");
Console.WriteLine("****************************************");
switch (Int16.Parse(Console.ReadLine()))
{
case 1: CreateFile(); break;
case 2: OpenFile(); break;
case 3: fl = false; break;
default: Console.WriteLine("Неверно введен пункт!"); break;
}
} while (fl);
}
public static void CreateFile()
{
try
{
Console.Write("Введите имя создаваемого файла: ");
FileStream fs = new FileStream(Console.ReadLine() + ".txt", FileMode.Create);
Console.WriteLine("ТЕКСТ СООБЩЕНИЯ: ");
string text = Console.ReadLine();
StreamWriter s = new StreamWriter(fs);
s.WriteLine(text);
s.Close();
}
catch (Exception ex)
{ Console.WriteLine("Ошибка создания файла: {0}", ex.Message); }
}
public static void OpenFile()
{
try
{
Console.WriteLine("Введите имя открываемого файла: ");
using (StreamReader sr = new StreamReader(Console.ReadLine()+".txt"))
{
string line;
Console.WriteLine("ТЕКСТ ИЗ ФАЙЛА: \n");
while ((line = sr.ReadLine()) != null)
{ Console.WriteLine(line); }
}
}
catch (Exception ex)
{ Console.WriteLine("Ошибка октрытия файла: {0}", ex.Message); }
}
}