Hello everyone,
My all codes are below. This codes are creating "mac.txt" file but I cant write any data in this file. I dont know what is the problem?
using System.Text;
using System.Windows.Forms;
using System.IO;
private void button1_Click(object sender, EventArgs e)
{
StreamWriter dosya = new StreamWriter("mac.txt");
dosya.WriteLine("1231231231");
dosya.Write("123123123");
}
Loading

VulpesRank #55 · 29.2K reputationPosted May 10, 2011, 1:08 AM EDT
StreamWriter dosya = new StreamWriter("mac.txt");
dosya.WriteLine("1231231231");
dosya.Write("123123123");
dosya.Close();
Another way to automatically close the stream is to use the 'using' statement:
using (StreamWriter dosya = new StreamWriter("mac.txt"))
{
dosya.WriteLine("1231231231");
dosya.Write("123123123");
}
omkar mhaiskar84 reputationPosted May 10, 2011, 1:30 AM EDT
just go through with your following code:-
string strFileName ="mac.txt";
FileStream fileStream = new FileStream(strFileName, FileMode.OpenOrCreate);
StreamWriter streamWriter = new StreamWriter(fileStream);
streamWriter.BaseStream.Seek(0, SeekOrigin.End);
//contents = contents.Replace("@date", DateTime.Today.ToString("dd/MM/yyyy"));
streamWriter.WriteLine("1231231231");
streamWriter.Write("1231231231");
streamWriter.Flush();
streamWriter.Close();
Sam HobbsRank #107 · 20.5K reputationPosted May 10, 2011, 9:32 PM EDT
VulpesRank #55 · 29.2K reputationPosted May 11, 2011, 5:44 AM EDT
Sam HobbsRank #107 · 20.5K reputationPosted May 11, 2011, 8:27 AM EDT
I have in the past had a problem with data being lost (not written) until I called Flush. Perhaps I did not call Close but if so then I am disappointed that Dispose or whatever it is that de-allocates the object does not do the Close.