.NET Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgramming.NET Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old October 4th, 2007, 02:11 AM
complete complete is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 43 complete User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 39 m 25 sec
Reputation Power: 3
My first C# program

I made my first C# program using Visual C# 2005 by just adding a few controls to the dialog box. It was pretty easy.

I am looking for a some C# code that shows how to use C# to open and read a file, one character at a time and output to another file. Any suggestions?

Reply With Quote
  #2  
Old October 28th, 2007, 08:34 AM
jey jey is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2007
Posts: 16 jey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 m 54 sec
Reputation Power: 0
i am also looking for this

Reply With Quote
  #3  
Old November 3rd, 2007, 08:01 PM
DrFace007 DrFace007 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2007
Posts: 3 DrFace007 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 43 m 39 sec
Reputation Power: 0
If you can do with a program that does not require reading the file one character at a time, then here is a solution:


Code:
using System;
using System.IO;

class ReadWriteExample
{
    static void Main(string[] args)
    {
        // Use FileStream to specify the files to use for reading and writing
        FileStream readFromThisFile = new FileStream(@"C:\abc.txt", FileMode.OpenOrCreate, FileAccess.Read);
        FileStream writeToThisFile = new FileStream(@"C:\xyz.txt", FileMode.OpenOrCreate, FileAccess.Write);
           
        // Create a stream called reader to read the data
        StreamReader reader = new StreamReader(readFromThisFile);

        // Put all of the data into the variable called contentsOfTextFile
        string contentsOfTextFile = reader.ReadToEnd();

        // Create a stream called Writer to write the data
        StreamWriter writer = new StreamWriter(writeToThisFile);

        // Put all the data which is in contentsOfTextFile to that file
        writer.Write(contentsOfTextFile);

        // Close the resources
        writer.Close();
        reader.Close();
        writeToThisFile.Close();
        readFromThisFile.Close();
    }
}



Although, this reads the entire file into one string rather than one character at a time.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgramming.NET Development > My first C# program


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT