How do I write a "Hello World" string stored in a (*.txt) file to the Console output?
-
How do I write a "Hello World" string stored in a (*.txt) file to the Console output? using System; using System.IO; //Is this the right idea?? //Please-- show me CODE not the "just use use a "-----" answer.... namespace StreamReaderWriter { /// /// Summary description for Class1. /// class Class1 { /// /// The main entry point for the application. /// [STAThread] static void Main(string[] args) { // TODO: Add code to start application here //@"C:\Documents and Settings\Desktop\Text01"; string file_name = (@"C:\Documents and Settings\Desktop\Text01"); StreamReader fReader = File.OpenText(file_name); StreamWriter fWriter = File.CreateText(@"C:\Documents and Settings\Desktop\Text01"); //Now, how do I get the "Hello World" in the text file to the console output?? } } } thanks a lot for your help.....
...---... wrote:
Please-- show me CODE not the "just use use a "-----" answer....
Have you tried reading the documentation for StreamReader? From MSN Search[^]you can find the top two links will take you to the StreamReader Class documentation[^]. There you will find a table with lots of handy "How to..." links. One of which takes you to Reading Text From A File[^] which shows you step-by-step exactly what you are trying to do. Does this help?
Upcoming Scottish Developers events: * UK Security Evangelists On Tour (2nd November, Edinburgh) * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog
-
How do I write a "Hello World" string stored in a (*.txt) file to the Console output? using System; using System.IO; //Is this the right idea?? //Please-- show me CODE not the "just use use a "-----" answer.... namespace StreamReaderWriter { /// /// Summary description for Class1. /// class Class1 { /// /// The main entry point for the application. /// [STAThread] static void Main(string[] args) { // TODO: Add code to start application here //@"C:\Documents and Settings\Desktop\Text01"; string file_name = (@"C:\Documents and Settings\Desktop\Text01"); StreamReader fReader = File.OpenText(file_name); StreamWriter fWriter = File.CreateText(@"C:\Documents and Settings\Desktop\Text01"); //Now, how do I get the "Hello World" in the text file to the console output?? } } } thanks a lot for your help.....
Sorry for my mistake, here is the correct line Console.WriteLine(fReader.ReadLine());
-
How do I write a "Hello World" string stored in a (*.txt) file to the Console output? using System; using System.IO; //Is this the right idea?? //Please-- show me CODE not the "just use use a "-----" answer.... namespace StreamReaderWriter { /// /// Summary description for Class1. /// class Class1 { /// /// The main entry point for the application. /// [STAThread] static void Main(string[] args) { // TODO: Add code to start application here //@"C:\Documents and Settings\Desktop\Text01"; string file_name = (@"C:\Documents and Settings\Desktop\Text01"); StreamReader fReader = File.OpenText(file_name); StreamWriter fWriter = File.CreateText(@"C:\Documents and Settings\Desktop\Text01"); //Now, how do I get the "Hello World" in the text file to the console output?? } } } thanks a lot for your help.....
...---... wrote:
show me CODE not the "just use use a "-----" answer....
Are you really that lazy?
:josh: My WPF Blog[^]
-
...---... wrote:
show me CODE not the "just use use a "-----" answer....
Are you really that lazy?
:josh: My WPF Blog[^]
Josh Smith wrote:
Are you really that lazy?
College is starting up again for the fall. Expect to see a majot upswing in 'do my homework for me' posts. The original poster is directed to here: http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.2[^]
-
How do I write a "Hello World" string stored in a (*.txt) file to the Console output? using System; using System.IO; //Is this the right idea?? //Please-- show me CODE not the "just use use a "-----" answer.... namespace StreamReaderWriter { /// /// Summary description for Class1. /// class Class1 { /// /// The main entry point for the application. /// [STAThread] static void Main(string[] args) { // TODO: Add code to start application here //@"C:\Documents and Settings\Desktop\Text01"; string file_name = (@"C:\Documents and Settings\Desktop\Text01"); StreamReader fReader = File.OpenText(file_name); StreamWriter fWriter = File.CreateText(@"C:\Documents and Settings\Desktop\Text01"); //Now, how do I get the "Hello World" in the text file to the console output?? } } } thanks a lot for your help.....
Process.Start("type filename"); :p
On two occasions I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question. - Charles Babbage
-
Process.Start("type filename"); :p
On two occasions I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question. - Charles Babbage
-
How do I write a "Hello World" string stored in a (*.txt) file to the Console output? using System; using System.IO; //Is this the right idea?? //Please-- show me CODE not the "just use use a "-----" answer.... namespace StreamReaderWriter { /// /// Summary description for Class1. /// class Class1 { /// /// The main entry point for the application. /// [STAThread] static void Main(string[] args) { // TODO: Add code to start application here //@"C:\Documents and Settings\Desktop\Text01"; string file_name = (@"C:\Documents and Settings\Desktop\Text01"); StreamReader fReader = File.OpenText(file_name); StreamWriter fWriter = File.CreateText(@"C:\Documents and Settings\Desktop\Text01"); //Now, how do I get the "Hello World" in the text file to the console output?? } } } thanks a lot for your help.....
for heavens sake, when a hint is given to you you should at least try it. Anyway, I also was happy when people helped me with my probs, so here is my suggestion: private void InitializeStreamReader() { System.IO.FileStream fstream = System.IO.File.OpenRead(@"c:\test.dat"); System.IO.StreamReader sreader = new System.IO.StreamReader(fstream); string[] filecontent = sreader.ReadToEnd().Split('\n'); sreader.Close(); foreach (string contentTemp in filecontent) { Console.WriteLine(contentTemp); } } Here is a short explanation what is done in this example: A Filestream is created A Streamreader which uses the Filestream the streamreader reads all the content of the file an splits it by the new lines (every new line is a new element) these elements are used in a string array the streamreader is being closed and now to the interesting part: every line in the string array is being displayed via console.writeline Of course it can be done easier, but I think you´ll like it this way as well
-
Process.Start("type filename"); :p
On two occasions I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question. - Charles Babbage
Ennis Ray Lynch, Jr. wrote:
On two occasions I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question. - Charles Babbage
Stealing my old signatures? :-D Would you steal my grave as quick? ;P
Upcoming Scottish Developers events: * UK Security Evangelists On Tour (2nd November, Edinburgh) * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog
-
for heavens sake, when a hint is given to you you should at least try it. Anyway, I also was happy when people helped me with my probs, so here is my suggestion: private void InitializeStreamReader() { System.IO.FileStream fstream = System.IO.File.OpenRead(@"c:\test.dat"); System.IO.StreamReader sreader = new System.IO.StreamReader(fstream); string[] filecontent = sreader.ReadToEnd().Split('\n'); sreader.Close(); foreach (string contentTemp in filecontent) { Console.WriteLine(contentTemp); } } Here is a short explanation what is done in this example: A Filestream is created A Streamreader which uses the Filestream the streamreader reads all the content of the file an splits it by the new lines (every new line is a new element) these elements are used in a string array the streamreader is being closed and now to the interesting part: every line in the string array is being displayed via console.writeline Of course it can be done easier, but I think you´ll like it this way as well
-
Ennis Ray Lynch, Jr. wrote:
On two occasions I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question. - Charles Babbage
Stealing my old signatures? :-D Would you steal my grave as quick? ;P
Upcoming Scottish Developers events: * UK Security Evangelists On Tour (2nd November, Edinburgh) * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog
With apologies, I just rotate through cool stuff I have copied and pasted in a sigs text file. Perhaps you can take it as a compliment rather than an offense :)
On two occasions I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question. - Charles Babbage
-
With apologies, I just rotate through cool stuff I have copied and pasted in a sigs text file. Perhaps you can take it as a compliment rather than an offense :)
On two occasions I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question. - Charles Babbage
Ennis Ray Lynch, Jr. wrote:
With apologies, .... Perhaps you can take it as a compliment
Oh no. I do take it as a compliment. I guess even the smilies around my very poor joke didn't work. (Since starting to work in Glasgow I'm picking up their very cynical sense of humour - And I move there next month so I guess it is going to get worse!)
Upcoming Scottish Developers events: * UK Security Evangelists On Tour (2nd November, Edinburgh) * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog
-
Ennis Ray Lynch, Jr. wrote:
With apologies, .... Perhaps you can take it as a compliment
Oh no. I do take it as a compliment. I guess even the smilies around my very poor joke didn't work. (Since starting to work in Glasgow I'm picking up their very cynical sense of humour - And I move there next month so I guess it is going to get worse!)
Upcoming Scottish Developers events: * UK Security Evangelists On Tour (2nd November, Edinburgh) * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog
Those damn irish, j/k
On two occasions I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question. - Charles Babbage