/// <summary> /// 写文件 /// </summary> /// <param name="path">绝对路径</param> /// <param name="fileBytes">文件的字节数组</param> public static void Write(string path, byte[] fileBytes) { ApplicationPath.CreateDirectory(path); FileStream stream = new FileStream(path, FileMode.Create); byte[] buf = new byte[4096]; using (MemoryStream ms = new MemoryStream(fileBytes)) { int count = 0; while ((count = ms.Read(buf, 0, buf.Length)) > 0) { stream.Write(buf, 0, count); } stream.Flush(); } stream.Close(); }
public bool Export <T>(string path, object[] objArr) where T : Attribute { if (objArr == null || objArr.Length <= 0 || string.IsNullOrEmpty(path)) { return(false); } if (!path.EndsWith(".xml")) { path += ".xml"; } string allPath = string.Concat(ApplicationPath.PersistentRootPath, path); ApplicationPath.CreateDirectory(allPath); XmlDocument doc = new XmlDocument(); XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", "utf-8", "yes"); XmlElement rootEle = doc.CreateElement("data"); foreach (object obj in objArr) { Dictionary <string, object> dataDic = InjectDataBinder.ReflectAllData <T>(obj); XmlElement element = doc.CreateElement(obj.GetType().Name); this.saveXml(doc, element, dataDic); rootEle.AppendChild(element); } doc.AppendChild(dec); doc.AppendChild(rootEle); doc.Save(allPath); #if UNITY_EDITOR AssetDatabase.Refresh(); #endif return(true); }