Advertisement
luk_per

lab_6_okienkowo

Apr 26th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.64 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. using System.IO; // przesztreń nazw zapewniająca odczytywaniu i zapisywanie do pliku
  7.  
  8. namespace zad_1
  9. {
  10.     public class Program
  11.     {
  12.  
  13.  
  14.         static FileStream fs; // zapewnia zapis, odczyt pliku
  15.         static StreamWriter sw;
  16.  
  17.         public static void zapis(string imie, string nazwisko, decimal rok)
  18.         {
  19.             fs = new FileStream("D:\\!!!Studia\\Semestr 4\\Moje\\Informatyka\\Labki\\lab_7\\message3.txt", FileMode.Append, FileAccess.Write);
  20.             sw = new StreamWriter(fs);
  21.  
  22.  
  23.  
  24.             sw.WriteLine(imie + " " + nazwisko + " " + " " + rok); // zapisaniu ciągu tekstowego
  25.             sw.Flush();  // czyści bufory i zapisuje do pliku
  26.             sw.Close(); // zamyka obiekt i czyści strumień
  27.             fs.Close();  //zamyka strumień i zwalnia zasoby
  28.         }
  29.  
  30.  
  31.         public static string odczyt()
  32.         {
  33.             StreamReader sr = new StreamReader("D:\\!!!Studia\\Semestr 4\\Moje\\Informatyka\\Labki\\lab_7\\message3.txt");
  34.             String line = sr.ReadToEnd(); // odczytuje znaki od bieżącej pozycji do końca
  35.             //Console.WriteLine(line);
  36.             // sr.BaseStream.Position = 0; // powrót na początek pliku
  37.             /* string[] words = line1.Split(' ', '\t');
  38.             foreach (string word in words)
  39.             {
  40.                 Console.WriteLine(word);
  41.             }
  42.             */
  43.             sr.Close();
  44.             return line;
  45.         }
  46.  
  47.  
  48.  
  49.  
  50.         static void Main(string[] args)
  51.         {
  52.  
  53.        
  54.         }
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement