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.Threading.Tasks;
- namespace K33_2020_01_18
- {
- class Program
- {
- static void Main(string[] args)
- {
- int a;
- while(true)
- {
- try
- {
- Console.Write("Podaj liczbę");
- a = int.Parse(Console.ReadLine());
- Console.WriteLine(a);
- break;
- }
- catch (Exception e)
- {
- //Console.WriteLine(e.Message);
- Console.Clear();
- Console.WriteLine("Błąd - podaj liczbę całkowitą " + e.Message);
- // Console.ReadKey();
- }
- }
- Console.ReadKey();
- }
- }
- }
- -------------------------------------------------------------------------------------------------------------
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.IO;
- namespace K._33_2020_01_05
- {
- class Program
- {
- static string czytaj_dane(string tresc)
- {
- Console.Write(tresc);
- string zwrot = Console.ReadLine();
- return zwrot;
- }
- static void zapisz_dane_do_pliku(string plik, string tresc)
- {
- Directory.CreateDirectory(Path.GetDirectoryName(plik));// pobranie z argumentu plik pełnej ścieżki i wybranie z niej tylko nazw katalogów i ich utworzenie
- FileStream p_zapisz = new FileStream(plik, FileMode.Create); // tworzymy strumień znaków połączony z plikiem w argumencie metody i trybie tworzenia Create
- StreamWriter p_s_zapisz = new StreamWriter(p_zapisz);// tworzymy strumień wyjściowy
- p_s_zapisz.Write(tresc);// zapisujemy ciągi znaków do pliku
- p_s_zapisz.Close();
- p_zapisz.Close();
- }
- static void czytaj_dane_z_pliku(string plik)
- {
- FileStream p_odczyt = new FileStream(plik, FileMode.Open); // tworzymy strumień znaków połączony z plikiem w argumencie metody i trybie Open
- StreamReader p_s_odczyt = new StreamReader(p_odczyt); //tworzymy strumień wejściowy
- string zwrot;
- while((zwrot = p_s_odczyt.ReadLine()) != null)
- {
- Console.WriteLine(zwrot);
- }
- p_s_odczyt.Close();
- p_odczyt.Close();
- }
- static void Main(string[] args)
- {
- string imie = czytaj_dane("Podaj imię: ");
- string nazwisko = czytaj_dane("Podaj nazwisko: ");
- zapisz_dane_do_pliku(@"test\e\e\dane.txt", imie + " " + nazwisko);
- czytaj_dane_z_pliku(@"test\e\e\dane.txt");
- //Directory.Delete(@"test", true); // do usuwania katalogu wraz z zawartością
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement