unity txt文件读取与写入


打开文件并写入:

void CreateOrOPenFile(string path, string name, string info){          //路径、文件名、写入内容
 StreamWriter sw; 
 FileInfo fi = new FileInfo(path + "//" + name);
 sw = fi.CreateText ();        //直接重新写入,如果要在原文件后面追加内容,应用fi.AppendText()
 sw.WriteLine(info);
 sw.Close();
 sw.Dispose ();
}

读取文件内容:

void LoadFileAndIntialSpeed (string sPath, string sName){
 StreamReader sr = null;
 sr = File.OpenText (sPath + "//" + sName);

 string t_Line;

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

  //do some thing with t_sLine

 } else {
 print ("Null!");
 }

 sr.Close ();
 sr.Dispose ();
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM