Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. // OrtizOL - xCSw - http://ortizol.blogspot.com
  2.  
  3. using System;
  4. using System.IO;
  5. using System.Text;
  6.  
  7. namespace Receta.CSharp.R0507
  8. {
  9.     public class LecturaEscrituraArchivo
  10.     {
  11.         public static void Main()
  12.         {
  13.             Console.WriteLine(Environment.NewLine);
  14.            
  15.             // Creación de archivo de texto plano:
  16.             using (FileStream fs = new FileStream("ArchivoTexto.txt", FileMode.Create))
  17.             {
  18.                 // Creación de objeto StreamWriter para la escritura
  19.                 // sobre el archivo recién creado. El sistema de
  20.                 // codificación es UTF-8:
  21.                 using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
  22.                 {
  23.                     // Escritura de diferentes tipos de datos:
  24.                     sw.WriteLine(987.65M);
  25.                     sw.WriteLine("OrtizOL - xCSw");
  26.                     sw.WriteLine('!');
  27.                 }
  28.             }
  29.            
  30.             Console.WriteLine("Para continuar con la lectura presione Enter.");
  31.             Console.ReadLine();
  32.            
  33.             // Apertura del archivo:
  34.             using (FileStream fs = new FileStream("ArchivoTexto.txt", FileMode.Open))
  35.             {
  36.                 using(StreamReader sr = new StreamReader(fs, Encoding.UTF8))
  37.                 {
  38.                     Console.WriteLine(Decimal.Parse(sr.ReadLine()));
  39.                     Console.WriteLine(sr.ReadLine());
  40.                     Console.WriteLine(Char.Parse(sr.ReadLine()));
  41.                 }
  42.             }
  43.            
  44.             Console.WriteLine(Environment.NewLine);
  45.         }
  46.     }
  47. }