fcamuso

Streams - 3a parte: StreamReader/Writer

Jul 27th, 2021
1,411
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.IO;
  3.  
  4. namespace StreamAdapters_A
  5. {
  6.   class Program
  7.   {
  8.     static void Main(string[] args)
  9.     {
  10.  
  11.       StreamReader test = new StreamReader("test.txt");
  12.       string s = test.ReadLine();
  13.  
  14.       //commento da scartare in lettura
  15.       //using (FileStream fs = new FileStream("..//..//../Program.cs",
  16.       //                                         FileMode.Open, FileAccess.Read))
  17.       //{        
  18.       //  using (StreamReader leggi = new StreamReader(fs))
  19.       //  {
  20.  
  21.  
  22.       //  }
  23.       //}
  24.  
  25.       using (StreamReader leggi = new StreamReader("..//..//../Program.cs"))
  26.       {
  27.         using (StreamWriter scrivi = new StreamWriter("ProgramSenzaCommenti.cs", true))
  28.         {
  29.           string rigaLetta = "";
  30.           while ((rigaLetta = leggi.ReadLine()) != null)
  31.             if (!rigaLetta.TrimStart().StartsWith("//"))
  32.               scrivi.WriteLine(rigaLetta);
  33.         }
  34.       }
  35.      
  36.      
  37.     }
  38.   }
  39. }
  40.  
RAW Paste Data