Last active
July 6, 2021 10:38
-
-
Save Mahno74/270b5132de8f2ff898feb0b6787e0d98 to your computer and use it in GitHub Desktop.
Запись в текстовый файл данных
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
using System.Text; | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
string readPath = @"D:\read.txt"; //путь для чтения файла | |
string writePath = @"D:\write.txt"; //пусть для записи файла | |
string text = ""; //буферная переменная | |
//Чтение | |
try | |
{ | |
using (StreamReader sr = new StreamReader(readPath, Encoding.Default)) //Чтение в переменную | |
{ | |
text = sr.ReadToEnd(); | |
} | |
using (StreamWriter sw = new StreamWriter(writePath, false, Encoding.Default)) //false - переписываем файл | |
{ | |
sw.WriteLine(text); | |
} | |
using (StreamWriter sw = new StreamWriter(writePath, true, Encoding.Default)) //true - дозаписываем файл | |
{ | |
sw.WriteLine("Bonus "); | |
sw.Write(4.5); | |
} | |
} | |
catch (Exception) | |
{ | |
throw; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment