c# 读入文本文件实用代码
/// <summary> /// 读入文件文本 /// </summary> /// <param name="txtfile">文件名</param> /// <returns></returns> public string Read(string txtfile) { //文件路径 string filePath = System.AppDomain.CurrentDomain.BaseDirectory + txtfile; string str = ""; try { if (File.Exists(filePath)) { str = File.ReadAllText(filePath); // byte[] mybyte = Encoding.UTF8.GetBytes(textBox1.Text); //textBox1.Text = Encoding.UTF8.GetString(mybyte); } } catch (Exception ex) { // MessageBox.Show(ex.Message); } return str; }