Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 02-23-2004, 06:44 AM   #1 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,487
sde is on a distinguished road
Read and Write to a Text File

This is a very simple way to read and write to a text file using TextReader and TextWriter.

First you need to include System.IO
Code:
using System.IO;
Reading a Text File:
Code:
static void Main(string[] args)
{
  // create reader & open file
  TextReader tr = new StreamReader("date.txt");

  // read a line of text
  Console.WriteLine(tr.ReadLine());

  // close the stream
  tr.Close();
}
Writting a Text File
Code:
static void Main(string[] args)
{
  // create a writer and open the file
  TextWriter tw = new StreamWriter("date.txt");

  // write a line of text to the file
  tw.WriteLine(DateTime.Now);

  // close the stream
  tw.Close();
}
__________________
Mike
sde is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Implementing C++ file structure in C# IAmWeasel MS Technologies ( ASP, VB, C#, .NET ) 1 07-08-2004 07:38 AM


All times are GMT -8. The time now is 10:13 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting