C#读写文件

2019-02-21  本文已影响0人  FANZY_d3fa

//路径、文件名、写入内容

        void CreateOrOPenFile(string path, string name, string info)

        {

            StreamWriter sw;

            FileInfo fi = new FileInfo(path + "//" + name);

            //直接重新写入,如果要在原文件后面追加内容,应用fi.AppendText()

            sw = fi.CreateText();       

            sw.WriteLine(info);

            sw.Close();

            sw.Dispose();

        }

        void LoadFileAndIntialSpeed(string sPath, string sName)

        {

            StreamReader sr = null;

            sr = File.OpenText(sPath + "//" + sName);

            string t_sLine;

            if ((t_sLine = sr.ReadLine()) != null)

            {

                //do some thing with t_sLine

            }

            else

            {

                //print("Null!");

            }

            sr.Close();

            sr.Dispose();

        }

上一篇 下一篇

猜你喜欢

热点阅读