Created
July 10, 2015 19:47
-
-
Save Fhernd/457ffa746e44ef3613ce to your computer and use it in GitHub Desktop.
Demostración de escritura y lectura de archivos de texto plano en C#.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// OrtizOL - xCSw - http://ortizol.blogspot.com | |
using System; | |
using System.IO; | |
using System.Text; | |
namespace Receta.CSharp.R0507 | |
{ | |
public class LecturaEscrituraArchivo | |
{ | |
public static void Main() | |
{ | |
Console.WriteLine(Environment.NewLine); | |
// Creación de archivo de texto plano: | |
using (FileStream fs = new FileStream("ArchivoTexto.txt", FileMode.Create)) | |
{ | |
// Creación de objeto StreamWriter para la escritura | |
// sobre el archivo recién creado. El sistema de | |
// codificación es UTF-8: | |
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8)) | |
{ | |
// Escritura de diferentes tipos de datos: | |
sw.WriteLine(987.65M); | |
sw.WriteLine("OrtizOL - xCSw"); | |
sw.WriteLine('!'); | |
} | |
} | |
Console.WriteLine("Para continuar con la lectura presione Enter."); | |
Console.ReadLine(); | |
// Apertura del archivo: | |
using (FileStream fs = new FileStream("ArchivoTexto.txt", FileMode.Open)) | |
{ | |
using(StreamReader sr = new StreamReader(fs, Encoding.UTF8)) | |
{ | |
Console.WriteLine(Decimal.Parse(sr.ReadLine())); | |
Console.WriteLine(sr.ReadLine()); | |
Console.WriteLine(Char.Parse(sr.ReadLine())); | |
} | |
} | |
Console.WriteLine(Environment.NewLine); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment