Advertisement
Guest User

Untitled

a guest
Jan 19th, 2020
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.07 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace K33_2020_01_18
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. int a;
  14. while(true)
  15. {
  16. try
  17. {
  18. Console.Write("Podaj liczbę");
  19. a = int.Parse(Console.ReadLine());
  20. Console.WriteLine(a);
  21. break;
  22. }
  23. catch (Exception e)
  24. {
  25. //Console.WriteLine(e.Message);
  26. Console.Clear();
  27. Console.WriteLine("Błąd - podaj liczbę całkowitą " + e.Message);
  28. // Console.ReadKey();
  29. }
  30. }
  31.  
  32.  
  33.  
  34. Console.ReadKey();
  35. }
  36. }
  37. }
  38.  
  39. -------------------------------------------------------------------------------------------------------------
  40. using System;
  41. using System.Collections.Generic;
  42. using System.Linq;
  43. using System.Text;
  44. using System.Threading.Tasks;
  45. using System.IO;
  46.  
  47. namespace K._33_2020_01_05
  48. {
  49. class Program
  50. {
  51. static string czytaj_dane(string tresc)
  52. {
  53. Console.Write(tresc);
  54. string zwrot = Console.ReadLine();
  55. return zwrot;
  56. }
  57.  
  58. static void zapisz_dane_do_pliku(string plik, string tresc)
  59. {
  60. Directory.CreateDirectory(Path.GetDirectoryName(plik));// pobranie z argumentu plik pełnej ścieżki i wybranie z niej tylko nazw katalogów i ich utworzenie
  61. FileStream p_zapisz = new FileStream(plik, FileMode.Create); // tworzymy strumień znaków połączony z plikiem w argumencie metody i trybie tworzenia Create
  62. StreamWriter p_s_zapisz = new StreamWriter(p_zapisz);// tworzymy strumień wyjściowy
  63. p_s_zapisz.Write(tresc);// zapisujemy ciągi znaków do pliku
  64. p_s_zapisz.Close();
  65. p_zapisz.Close();
  66.  
  67. }
  68.  
  69. static void czytaj_dane_z_pliku(string plik)
  70. {
  71. FileStream p_odczyt = new FileStream(plik, FileMode.Open); // tworzymy strumień znaków połączony z plikiem w argumencie metody i trybie Open
  72. StreamReader p_s_odczyt = new StreamReader(p_odczyt); //tworzymy strumień wejściowy
  73. string zwrot;
  74. while((zwrot = p_s_odczyt.ReadLine()) != null)
  75. {
  76. Console.WriteLine(zwrot);
  77. }
  78. p_s_odczyt.Close();
  79. p_odczyt.Close();
  80. }
  81.  
  82. static void Main(string[] args)
  83. {
  84. string imie = czytaj_dane("Podaj imię: ");
  85. string nazwisko = czytaj_dane("Podaj nazwisko: ");
  86. zapisz_dane_do_pliku(@"test\e\e\dane.txt", imie + " " + nazwisko);
  87. czytaj_dane_z_pliku(@"test\e\e\dane.txt");
  88. //Directory.Delete(@"test", true); // do usuwania katalogu wraz z zawartością
  89. Console.ReadKey();
  90.  
  91. }
  92. }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement