View Single Post
  #23 (permalink)  
Old 08-26-2008, 08:55 PM
PlayaSkater's Avatar   
PlayaSkater PlayaSkater is offline
Learning Programmer
 
Join Date: Aug 2007
Location: Cruzer, US
Age: 18
Posts: 63
Credits: 0
Rep Power: 6
PlayaSkater is on a distinguished road
Default Re: C# Tutorial: Writing Text Files

Hey, Xav, let's say I wanted the console to pop up and I would enter the text myself to be written to the text file. Here's the code I have, but it doesn't seem to be working. The console leaves immediately:

Code:
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

public class writetext
{
    static void Main()
    {
        //Ask for text to write to buffer
        Console.WriteLine("What would you like to write to text file?  ");
        string buffer = Console.ReadLine();
       

        //Write buffer to textfile
        string path = @"C:/Users/MyName/Documents/C# file.txt";
        StreamWriter txtwrite = new StreamWriter(path);
        txtwrite.WriteLine(buffer);
        txtwrite.Close();
    }
}
Reply With Quote