Lost Password?


  #21 (permalink)  
Old 08-25-2008, 02:30 PM
amrosama's Avatar   
amrosama amrosama is offline
Guru
 
Join Date: Aug 2007
Location: egypt
Age: 20
Posts: 2,021
Last Blog:
OO Life
Rep Power: 21
amrosama is a jewel in the roughamrosama is a jewel in the roughamrosama is a jewel in the roughamrosama is a jewel in the rough
Send a message via MSN to amrosama
Default Re: C# Tutorial: Writing Text Files

ohh right sorry dude
__________________
A good programmer is someone who always looks both ways before crossing a one-way street
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #22 (permalink)  
Old 08-25-2008, 02:32 PM
Xav's Avatar   
Xav Xav is offline
Code Warrior
 
Join Date: Mar 2008
Location: On God's Planet
Posts: 9,589
Last Blog:
Web slideshow in JavaS...
Rep Power: 76
Xav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud of
Send a message via MSN to Xav
Default Re: C# Tutorial: Writing Text Files

He he lol it's alright. It would be a good idea to call Dispose() after you call Close(), just to be on the safe side.
__________________


Mr. Xav | Website | Forums | Blog
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #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: 17
Posts: 63
Rep Power: 5
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();
    }
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #24 (permalink)  
Old 08-27-2008, 09:47 AM
Xav's Avatar   
Xav Xav is offline
Code Warrior
 
Join Date: Mar 2008
Location: On God's Planet
Posts: 9,589
Last Blog:
Web slideshow in JavaS...
Rep Power: 76
Xav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud of
Send a message via MSN to Xav
Default Re: C# Tutorial: Writing Text Files

What do you mean by "leaves immediately"? Where does it go? Is the file still written?
__________________


Mr. Xav | Website | Forums | Blog
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #25 (permalink)  
Old 08-27-2008, 10:07 AM
amrosama's Avatar   
amrosama amrosama is offline
Guru
 
Join Date: Aug 2007
Location: egypt
Age: 20
Posts: 2,021
Last Blog:
OO Life
Rep Power: 21
amrosama is a jewel in the roughamrosama is a jewel in the roughamrosama is a jewel in the roughamrosama is a jewel in the rough
Send a message via MSN to amrosama
Default Re: C# Tutorial: Writing Text Files

Quote:
Originally Posted by PlayaSkater View Post
The console leaves immediately
same here and nothing is writen to the text file, but the same code works on a windows application
__________________
A good programmer is someone who always looks both ways before crossing a one-way street
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #26 (permalink)  
Old 08-27-2008, 10:28 AM
Xav's Avatar   
Xav Xav is offline
Code Warrior
 
Join Date: Mar 2008
Location: On God's Planet
Posts: 9,589
Last Blog:
Web slideshow in JavaS...
Rep Power: 76
Xav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud of
Send a message via MSN to Xav
Default Re: C# Tutorial: Writing Text Files

I don't understand. Where does it leave, and what's the problem?
__________________


Mr. Xav | Website | Forums | Blog
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #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: 17
Posts: 63
Rep Power: 5
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();
    }
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #28 (permalink)  
Old 08-28-2008, 07:06 AM
PlayaSkater's Avatar   
PlayaSkater PlayaSkater is offline
Learning Programmer
 
Join Date: Aug 2007
Location: Cruzer, US
Age: 17
Posts: 63
Rep Power: 5
PlayaSkater is on a distinguished road
Default Re: C# Tutorial: Writing Text Files

There is a new problem now. The text writes fine to the .txt file, but it cuts off the first letter. Don't ask me why, but do you have an idea of what the problem could be?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #29 (permalink)  
Old 08-28-2008, 09:39 AM
Xav's Avatar   
Xav Xav is offline
Code Warrior
 
Join Date: Mar 2008
Location: On God's Planet
Posts: 9,589
Last Blog:
Web slideshow in JavaS...
Rep Power: 76
Xav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud of
Send a message via MSN to Xav
Default Re: C# Tutorial: Writing Text Files

It's that new line - Console.Read() reads a single character from the input. Therefore, when you type, the first letter goes to the Console.Read() bit, and the rest goes to the Console.ReadLine(), which is put in the buffer. Therefore, try this instead:
Code:
string buffer = Console.Read().ToString() + Console.ReadLine();
__________________


Mr. Xav | Website | Forums | Blog
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #30 (permalink)  
Old 08-31-2008, 04:58 AM
squire6677 squire6677 is offline
Banned
 
Join Date: Aug 2008
Posts: 3
Rep Power: 0
squire6677 is on a distinguished road
Default Re: C# Tutorial: Writing Text Files

thnx i need that
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
Reply

Tags
file, text, tutorial, writing



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Tutorial: Storing Images in MySQL with PHP Jordan PHP Tutorials 13 09-23-2008 07:11 PM
Text files travy92 Visual Basic Programming 1 10-07-2007 11:06 AM
How to style fonts of a text in a simple page? c0de Tutorials 3 09-15-2007 11:08 PM
HTML Basic Formatting clookid Tutorials 14 03-06-2007 04:10 PM
John's Java Tutorial Index John Java Tutorials 0 01-11-2007 04:05 PM


All times are GMT -5. The time now is 12:32 PM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 98%

Ads