簡單記錄一下,不喜勿噴
讀取文件方法
public void ReadAccount() { string[] RawString = System.IO.File.ReadAllLines(@"Data\Account.txt"); //路徑 for(int i = 0; i < RawString.Length; i++) // { string[] ss = RawString[i].Split(' '); //截斷字節 Account.Add(ss[0], ss[1]); //保存到字典里面 自己創建一個字典 } }
寫入文件方法
public static void WriteAccount() { string text = ""; foreach(var item in Account) { text += item.Key + " " + item.Value + "\r\n"; // \r\n 是換行符, 只有\n不會換行 } System.IO.File.WriteAllText(@"Data\Account.txt",text,Encoding.UTF8); }
/寫入文件方法
void OnApplicationQuit() { Debug.Log("執行了么"); string text = "";//\r\n表示換一行 兩行就是\r\n\r\n string text0 = ""; string text1 = ""; StreamWriter sw = new StreamWriter(Application.streamingAssetsPath + patch, true); if (Dicteory_List.instance.Dic_dic.Count != 0) { foreach (var item in Dicteory_List.instance.Dic_dic) { text0 = Dic_dic [item.Key].jianjie + "*" + Dic_dic[item.Key].shuxing + "*" + Dic_dic[item.Key].shuxing1 + "*" + Dic_dic[item.Key].cansu + "*" + Dic_dic[item.Key].cansu1 + "*" + Dic_dic[item.Key].danwei + "*" + Dic_dic[item.Key].danwei1 + "*"; text1 += item.Key + "*" + text0 + "\r\n"; } text = text1; sw.Write(text); sw.Flush(); sw.Close(); } }