Advertisement
Guest User

Untitled

a guest
May 20th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.50 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3.  
  4.  
  5. namespace TxtFileSizeGenerator
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             while (true)
  12.             {
  13.                 Console.WriteLine("Byte, Kb or Mb");
  14.                 string ans = Console.ReadLine();
  15.                 File.Delete("txt.txt");
  16.                 switch (ans.ToLower())
  17.                 {
  18.                     case "byte":
  19.                         Console.WriteLine("Successfully Saved");
  20.                         Console.WriteLine("");
  21.                         randomString(1, "byte");
  22.                         break;
  23.                     case "kb":
  24.                         Console.WriteLine("Successfully Saved");
  25.                         Console.WriteLine("");
  26.                         randomString(1, "kb");
  27.                         break;
  28.                     case "mb":
  29.                         Console.WriteLine("");
  30.                         randomString(1024, "mb");
  31.                         break;
  32.  
  33.                 }
  34.             }
  35.         }
  36.  
  37.         static void randomString(int size, string type)
  38.         {
  39.             Console.WriteLine("How Many?");
  40.             int amount;
  41.             if (!int.TryParse(Console.ReadLine(), out amount))
  42.             {
  43.                 Console.WriteLine("Error, this is a text only field");
  44.             }
  45.             else
  46.             {
  47.                 char[] letters = "qwertyuiopasdfghjklzxcvbnm1234567890".ToCharArray();
  48.                 Random r = new Random();
  49.                 string random = string.Empty;
  50.                 for (int i = 0; i < 1 * size; i++)
  51.                 {
  52.                     random += letters[r.Next(0, 35)].ToString();
  53.                 }
  54.                 if (type != "byte")
  55.                 {
  56.                     for (int i = 0; i < 1024 * amount; i++)
  57.                     {
  58.                         File.AppendAllText("txt.txt", random);
  59.                     }
  60.                     Console.WriteLine("Successfully Saved");
  61.                     System.Threading.Thread.Sleep(2000);
  62.                     Console.Clear();
  63.                 }
  64.                 else
  65.                 {
  66.                     for (int i = 0; i < amount; i++)
  67.                     {
  68.                         File.AppendAllText("txt.txt", random);
  69.                     }
  70.                     Console.WriteLine("Successfully Saved");
  71.                     System.Threading.Thread.Sleep(2000);
  72.                     Console.Clear();
  73.                 }
  74.             }
  75.         }
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement