View Single Post
  #27 (permalink)  
Old 08-28-2008, 07:02 AM
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

I'm sorry for the misunderstanding. What I meant was that console doesn't stay up so that I can enter the text in. But I got it to work now. Small overlooked error:

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?  ");
        Console.Read();
        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();
        txtwrite.Dispose();
    }
}
Reply With Quote