private void button2_Click(object sender, EventArgs e) { try { string buffer; StringBuilder stb = new StringBuilder(); StreamReader strmRdr = File.OpenText("c:\\testfile.txt"); while ((buffer = strmRdr.ReadLine()) != null) { stb.Append(buffer); stb.Append(Environment.NewLine); } textBox1.Text = stb.ToString(); strmRdr.Close(); } catch (IOException ex) { Console.WriteLine("Error in handling file!\n" + ex.Message.ToString()); } }
Saturday, February 4, 2012
Reading Text from Files (C#.net)
Labels:
C#.net,
StreamReader,
StringBuilder
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment