Hola:
Me ha enviado un archivo en CMD de broma que me llena los PenDrive de 8 GB a tope. En mi caso le quiero devolver la jugada en plan broma y lo único que se me ocurre es esto. Tarda en escribirse, pero él lo hacía más rapido que mi método. ¿Alguien le sale mejor?
Código:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO; // No olvidar desde aquí.
namespace CMD_Serie
{
class Program
{
private const string FILE_NAME = "Archivo.txt";
static void Main(string[] args)
{
if (File.Exists(FILE_NAME))
{
Console.WriteLine("{0} ya existe.", FILE_NAME);
Console.ReadKey();
return;
}
using (StreamWriter sw = File.CreateText(FILE_NAME))
{
for (long i = 1; i <= 999999999999999999; i++)
{
Console.WriteLine(i);
sw.WriteLine(i);
//sw.Close();
}
}
}
}
}
Saludo.