简单记录一下,不喜勿喷
读取文件方法
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(); } }