Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- namespace Test_plikow
- {
- class Program
- {
- static void Main(string[] args)
- {
- string path = @"plik.txt";//zmienna path zawiera ścieżkę
- StreamWriter sw;
- if(!File.Exists(path))//sprawdza czy plik istnieje(! neguje odpowiedź)
- {
- sw = File.CreateText(path);
- }
- else
- {
- sw = new StreamWriter(path,true);
- }
- string tekst = Console.ReadLine();
- sw.WriteLine(tekst);
- sw.Close();
- StreamReader sr = File.OpenText(path);
- string odczyt = "";
- int linia = 1;
- while ((odczyt = sr.ReadLine()) != null)
- {
- Console.WriteLine(linia++ + ". " + odczyt);
- }
- sr.Close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment