martes, 9 de diciembre de 2008

Ejemplo 3

using System;
using System.IO;
using System.Text;


namespace ConsoleApplication1
{
public class CEscribirCars
{
static void Main(string[] args)
{
StreamWriter sw = null;
string str;
try
{
//Crar un flujo hacia el fichero doc.txt
sw = new StreamWriter("C:\\doc\\doc.txt");
Console.WriteLine("Escriba las lineas de texto a almacenar en el fichero.\n" +
"Finalice cada linea pulsando la tecla .\n" +
"Para finalizar solo pulse la tecla .\n");
//Leer la linea de la entrada estandar
str = Console.ReadLine();
while (str.Length != 0)
{
//Escribir la linea leida en el fichero
sw.WriteLine(str);
//Leer la linea siguiente
str = Console.ReadLine();
}
}
catch (IOException e)
{
Console.WriteLine("Error:" + e.Message);
}
finally
{
if (sw != null) sw.Close();
}
}
}
}



No hay comentarios: