public static void WriteFile() { string path = Path.Combine(AssetBundleOutputPath, BuildUtil.GetPlatformFolder(EditorUserBuildSettings.activeBuildTarget)); path = path + "/assetMD5.txt"; string UpdaPath = Path.Combine(AssetBundleOutputPath, BuildUtil.GetPlatformFolder(EditorUserBuildSettings.activeBuildTarget)); UpdaPath = UpdaPath + "/updata.txt"; Dictionary <string, string> md5OldDict = new Dictionary <string, string>(); Dictionary <string, string> md5ChangDict = new Dictionary <string, string>(); if (File.Exists(path))//如果存在就删除 { StreamReader sr = new StreamReader(path, Encoding.Default); String line; while ((line = sr.ReadLine()) != null) { String[] md5 = line.Split(':'); if (!md5OldDict.ContainsKey(md5[1])) { if (md5.Length >= 3) { md5OldDict.Add(md5[1], md5[3]); } } else { Debug.LogError("have same key :" + md5[1]); } } sr.Dispose(); sr.Close(); //资源更新完才能删 File.Delete(path); } FileStream fs = new FileStream(path, FileMode.Create); StreamWriter sw = new StreamWriter(fs); sw.Write("Version:" + PlayerSettings.bundleVersion + "\r\n"); //sw.Write(System.Environment.NewLine); sw.Write("VersionCode:" + PlayerSettings.Android.bundleVersionCode + "\r\n"); //sw.Write(System.Environment.NewLine); long size = 0; //开始写入 foreach (KeyValuePair <string, string> kvp in md5Dict) { if (!md5OldDict.ContainsKey(kvp.Key)) { if (md5ChangDict.ContainsKey(kvp.Key)) { Debug.LogError("have same key :" + kvp.Key); } else { md5ChangDict.Add(kvp.Key, kvp.Value); } } if (SizeDict.ContainsKey(kvp.Key)) { size = SizeDict[kvp.Key]; } sw.Write("Name:" + kvp.Key + ":" + "MD5:" + kvp.Value + ":Size:" + size + "\r\n"); // sw.Write("MD5:" + kvp.Key + ": Name:" + kvp.Value); //sw.Write(System.Environment.NewLine); } //清空缓冲区 sw.Flush(); //关闭流 sw.Close(); fs.Close(); if (File.Exists(UpdaPath))//如果存在就删除 { File.Delete(UpdaPath); } fs = new FileStream(UpdaPath, FileMode.Create); sw = new StreamWriter(fs); foreach (KeyValuePair <string, string> kvp in md5ChangDict) { sw.Write("Name:" + kvp.Key + ":" + "MD5:" + kvp.Value + "\r\n"); // sw.Write("MD5:" + kvp.Key + ": Name:" + kvp.Value); //sw.Write(System.Environment.NewLine); } //清空缓冲区 sw.Flush(); //关闭流 sw.Close(); fs.Close(); }