System IO - Mobile Info
Amy is a data entry operator in a mobile company; she needs to store some information about the mobiles in a file name MobileInfo.txt. If the file exists, the new content must be appended to its end. How can you help her to perform this task using a console application?
Sample Input/Output Statements:
Enter a Sentence(or Press enter key to stop reading) :
Micormax becomes 10th Largest Mobile Phone Brand world wide
Enter a Sentence(or Press enter key to stop reading) :
Samsung Galaxy S6 sales off to a better start than Galaxy S5
Enter a Sentence(or Press enter key to stop reading) :
Mobile Information stored successfully
--------------------
Here is my code which is givinh runtime error
//codeusing System;
using System.IO;
namespace csharp_station.howto
{
class TextFileWriter
{
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
System.IO.StreamWriter tw =
new System.IO.StreamWriter("MobileInfo.txt", true);
Console.WriteLine("Enter a Sentence(or Press enter key to stop reading) :");
Console.ReadLine();
tw.WriteLine("Micormax becomes 10th Largest Mobile Phone Brand world wide ");
///Console.WriteLine("Enter a Sentence(or Press enter key to stop reading) :");
//Console.ReadLine();
tw.WriteLine("Enter a Sentence(or Press enter key to stop reading) :");
tw.WriteLine("Samsung Galaxy S6 sales off to a better start than Galaxy S5 ");
//Console.WriteLine("Enter a Sentence(or Press enter key to stop reading) :");
// Console.ReadLine();
tw.WriteLine("Enter a Sentence(or Press enter key to stop reading) :");
tw.WriteLine("Mobile Information stored successfully");
// close the stream
tw.Close();
}
}
}
Loading
Mohammed IbrahimPosted Aug 26, 2015, 10:01 AM
String x;
Console.WriteLine("Enter a Sentence(or Press enter key to stop reading) :");
x=Console.ReadLine();
do{
if(x!="")
{
tw.WriteLine(x);
Console.WriteLine("stored successfully");
}
else
{
break;
}
}
while(x=="");
tw.Close();
Shilpesh SinhaPosted Aug 26, 2015, 6:57 AM
using System;
namespace testing
{
class Program
{
static void Main(string[] args)
{
System.IO.StreamWriter tw =new System.IO.StreamWriter("MobileInfo.txt", true);
String x;
do
{
Console.WriteLine("Enter a Sentence(or Press enter key to stop reading) :");
x=Console.ReadLine();
if(x!="")
tw.WriteLine(x);
else
break;
}while(true);
Console.WriteLine("Mobile Information stored successfully");
// close the stream
}
}
}
Mohammed IbrahimPosted Aug 23, 2015, 4:53 AM
Upendra Pratap ShahiPosted Aug 23, 2015, 4:43 AM
Mohammed IbrahimPosted Aug 23, 2015, 4:09 AM
namespace demos
{
class Program
{
public static void Main(string[] args)
{
System.IO.StreamWriter textwriter = new System.IO.StreamWriter("demonotes.txt", true);
Console.WriteLine("Hi, Dude How are you??");
string reply=Console.ReadLine();
DateTime date=DateTime.Now;
textwriter.WriteLine("\n"+date);
textwriter.WriteLine(reply.ToString());
textwriter.Close();
}
}
}
Shilpesh SinhaPosted Aug 22, 2015, 12:56 PM
Mohammed IbrahimPosted Aug 22, 2015, 2:52 AM
Shilpesh SinhaPosted Aug 21, 2015, 10:38 AM
Mohammed IbrahimPosted Aug 21, 2015, 9:02 AM
* User: mohammedibrahim
* Date: 8/21/2015
* Time: 5:49 PM
*/
using System;
namespace testing
{
class Program
{
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
System.IO.StreamWriter tw =
new System.IO.StreamWriter("MobileInfo.txt", true);
Console.WriteLine("Enter a Sentence(or Press enter key to stop reading) :");
Console.ReadLine();
tw.WriteLine("Micormax becomes 10th Largest Mobile Phone Brand world wide ");
///Console.WriteLine("Enter a Sentence(or Press enter key to stop reading) :");
//Console.ReadLine();
tw.WriteLine("Enter a Sentence(or Press enter key to stop reading) :");
tw.WriteLine("Samsung Galaxy S6 sales off to a better start than Galaxy S5 ");
//Console.WriteLine("Enter a Sentence(or Press enter key to stop reading) :");
// Console.ReadLine();
tw.WriteLine("Enter a Sentence(or Press enter key to stop reading) :");
tw.WriteLine("Mobile Information stored successfully");
// close the stream
tw.Close();
}
}
}
Shilpesh SinhaPosted Aug 21, 2015, 8:57 AM
thank you
Mohammed IbrahimPosted Aug 21, 2015, 8:45 AM
Shilpesh SinhaPosted Aug 21, 2015, 8:39 AM
Mohammed IbrahimPosted Aug 21, 2015, 8:23 AM
Shilpesh SinhaPosted Aug 21, 2015, 7:59 AM
Sumit JoshiPosted Aug 21, 2015, 5:19 AM
Shilpesh SinhaPosted Aug 21, 2015, 5:13 AM
Sumit JoshiPosted Aug 21, 2015, 5:00 AM