Graduately/content/programovani/4-rocnik/05-soubory.md
pepaskopec-blip 333085ee53 Add a C# course with a side-by-side code runner.
Each lesson explains a topic and runs the edited program next to the text through the local .NET SDK.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-11 14:37:14 +02:00

747 B

id nazev popis
cs-4-soubory Soubory Zápis a čtení textu.

Výklad

WriteAllText

jednou

  • File.WriteAllText zapíše celý soubor. Když existuje, přepíše ho.
  • Cesta pozdrav.txt je vedle programu, v jeho složce.
  • ReadAllText celý text vrátí jako string.

Tip: Na telefonu se soubor nespustí. Na počítači s .NET ano.

Řádky

Append

  • AppendAllText přidá na konec a soubor nesmaže.
  • ReadAllLines vrátí pole řádků.
  • Po skončení programu soubor ve složce laboratoře zůstane.

Tip: Spusťte dvakrát. Druhý zápis WriteAllText starý text nahradí.

Kód

File.WriteAllText("pozdrav.txt", "Ahoj ze souboru");
string zpet = File.ReadAllText("pozdrav.txt");
Console.WriteLine(zpet);