How to merge two text files

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Dec 2008
Posts: 13
Reputation: nmakkena is an unknown quantity at this point 
Solved Threads: 0
nmakkena nmakkena is offline Offline
Newbie Poster

How to merge two text files

 
0
  #1
Jan 10th, 2009
Hi

i want to merge two text files.i.e. the content of the second file has to append to the content of the first file. pls help me out

Thanks
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: How to merge two text files

 
0
  #2
Jan 10th, 2009
Firstly, think of how you would want to do it, write it down.
Work out some code that looks like it should do what you wanted.
try it, what does it do?
if it doesnt work, post it, explain what you're getting you didnt expect, and ask for assistance.

Dont post just asking for us to do it for you
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 1,946
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 280
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Posting Virtuoso

Re: How to merge two text files

 
0
  #3
Jan 10th, 2009
Open the first file with FileMode.Append.
Open the file to append with FileMode.Open.
Read the file to append into a byte array.
Write the byte array to the first file.
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 46
Reputation: BlackSun is an unknown quantity at this point 
Solved Threads: 4
BlackSun BlackSun is offline Offline
Light Poster

Re: How to merge two text files

 
0
  #4
Jan 10th, 2009
hi
try using namespace System.IO;you will find two classes responsible for reading and writing from file with more options are :
- StreamReader ;
- StreamWriter ;
u can read ur file using StreamReader the write it using StreamWriter
but after using ur StreamReader and Writer close them EX :
StreamReader sr = new StreamReader(Strin Path);
TextBox1.Text=sr.ReadLine();
sr.close(); ------------> close reader;

and the same with Writer ;

there is another class File contains static members
File.ReadAllText();
File.WriteAllText();
File.open(string path , filemode.append);

all these depends on ur application if u wana preview ur text file and append with another file or u wanna do ur method during procesisng ur code ;

there is more but that easy ways u can append ur txt files

bye
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 1,946
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 280
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Posting Virtuoso

Re: How to merge two text files

 
0
  #5
Jan 10th, 2009
Originally Posted by BlackSun
TextBox1.Text=sr.ReadLine();
ReadLine reads a file untill the next \n character, this line is then put into a textbox. Nice.
What's the relevancy with this question ?
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 46
Reputation: BlackSun is an unknown quantity at this point 
Solved Threads: 4
BlackSun BlackSun is offline Offline
Light Poster

Re: How to merge two text files

 
0
  #6
Jan 11th, 2009
yeah u right
but u can use method "ReadToEnd" for multiline controls

StreamReader sr = new StreamReader(---------);
TextBox1.text = sr.ReadToEnd();
so ur reader will return all readed data ......
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 1,946
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 280
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Posting Virtuoso

Re: How to merge two text files

 
0
  #7
Jan 11th, 2009
That's very inventive BlackSun.
But if I drink wine I use a wineglass.
When I drink a coffee I use a coffeecup.
Do you drink wine from a coffeecup?
Don't use a textbox for this, but use a string.
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC