public void GetPag(int getId)
        {
            tagId = getId;
        }   取出来的这个 tagId  值,保存到txt 文本里边取名叫 text.txt然后怎么在把这个值取出来。。希望大神能帮忙。

解决方案 »

  1.   

    StreamWriter   writer   =   new   StreamWriter()---写
    StreamReader   sr   =   new   StreamReader()----读
     using system.io
    参考
      

  2.   

    openFileDialog1.Filter = "文本文件(*.txt)|*.txt";
    openFileDialog1.ShowDialog();
    textBox1.Text=openFileDialog1.FileName;
    StreamReader SR=new StreamReader(textBox1.Text,Encoding.Default);
    textBox2.Text=SR.ReadLine();
      

  3.   

    System.IO.File.WriteAllText("text.txt",tagId.ToString());
      

  4.   


    StreamWriter sw = File.AppendText(txtFilePath); 
    sw.WriteLine("test");
    sw.Flush();
    sw.Close(); 读
        StreamReader fileStream = new StreamReader(txtFilePath,Encoding.Default);
        txtContent.Text = fileStream.ReadToEnd();
      

  5.   

    StreamWriter w = new StreamWrited(sPath);
    w.WriteLine(i.tostring());
    w.close();
      

  6.   

            //存储的文件名
            private const string SettingFileName = "\text.txt";        /// <summary>
            /// 保存配置
            /// </summary>
            /// <param name="tagId">保存的值 tagId</param>
            /// <param name="appPath">存放的路径</param>
            public static void SaveSetting(string tagId, string appPath)
            {
                try
                {
                    string fullName = appPath + SettingFileName;
                    if (!Directory.Exists(appPath))
                        Directory.CreateDirectory(appPath);
                    if (!File.Exists(fullName))
                    {
                        FileStream fs = File.Create(fullName);
                        fs.Close();
                    }
                    StreamWriter sw = new StreamWriter(fullName, false);
                    sw.WriteLine(tagId);
                    sw.Close();
                }
                catch { }
            }
            /// <summary>
            /// 获得配置文件的信息
            /// </summary>
            /// <param name="appPath">文件所在位置</param>
            /// <returns></returns>
            public static string GetSetting(string appPath)
            {
                string tagId = string.Empty;
                try
                {
                    string fullName = appPath + SettingFileName;
                    if (!Directory.Exists(appPath))
                        Directory.CreateDirectory(appPath);
                    if (!File.Exists(fullName))
                    {
                        FileStream fs = File.Create(fullName);
                        fs.Close();
                    }
                    StreamReader sr = new StreamReader(fullName);
                    while (!sr.EndOfStream)
                    {
                        string strLine = sr.ReadLine();
                        if (strLine != "")
                        {
                            tagId = strLine;
                        }
                    }
                    sr.Close();
                }
                catch { }
                return tagId;
            }