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