码迷,mamicode.com
首页 > 其他好文 > 详细

xml常用方法

时间:2016-06-24 10:32:01      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:

using UnityEngine;
using System.Collections;
using System.IO;
/// <summary>
/// Move file.
/// 移动文件,
/// </summary>
public class MoveFile : MonoBehaviour {

// Use this for initialization
void Start () {
Debug.Log (Application.persistentDataPath);
//创建文件夹
//CreateFolder(Application.persistentDataPath,"test");

//移动文件
//MoveFileWithXML (Application.dataPath + @"/TestXml.xml" , Application.persistentDataPath+"/李佳/"+@"/TestXml.xml");

//复制文件
//CopyFileWithXML(Application.dataPath + @"/TestXml.xml" , Application.persistentDataPath+"/李佳/"+@"/TestXml.xml",true);

//查看文件夹是否存在
//FolderIsExist("李佳");
//bool k = fileOrfodlerExists (Application.persistentDataPath, "D.assetbundle", true);
//Debug.Log (k);

}

 

// Update is called once per frame
void Update () {

}

#region 创建文件夹
private void CreateFolder(string folderPath,string folderName)
{
Directory.CreateDirectory(folderPath+@"/"+folderName);
//Directory.CreateDirectory(Application.persistentDataPath+@"/李佳");
}
#endregion

#region 判断文件夹是否存在
//判断文件夹
private void FolderIsExist(string folderName)
{
if (Directory.Exists (Application.persistentDataPath + "/"+folderName)) {
Debug.Log ("文件夹存在");
} else {
Debug.Log ("文件夹不存在");
}
}
//判断文件和文件夹结合
//true----文件 false-----文件夹
public static bool fileOrfodlerExists(string path,string fileName,bool fileOrfodler)
{
if (fileOrfodler == true)
{
//判断文件是否存在
if (File.Exists (path +"/"+ fileName))
{
Debug.Log (fileName + "---文件存在");
return true;
}
else
{
Debug.Log (fileName + "---文件不存在");
return false;
}
}
else
{
//判断文件是否存在
if (Directory.Exists (path +"/"+ fileName))
{
Debug.Log (fileName + "---文件夹存在");
return true;
}
else
{
Debug.Log (fileName + "---文件夹不存在");
return false;
}
}
}
#endregion

#region 复制文件方法 文件复制方法:File.Copy
//A_dataPath---原始路径,B_dataPath----需要移动到的路径,overwrite---是否覆盖同名文件
public static void CopyFileWithXML(string A_dataPath,string B_dataPath,bool overwrite)
{
File.Copy(A_dataPath,B_dataPath,true);
}
#endregion

#region 文件移动方法:File.Move
//A_dataPath---原始路径,B_dataPath----需要移动到的路径
//磁盘位置要相同否则出错
private void MoveFileWithXML(string A_dataPath,string B_dataPath)
{
if (!File.Exists (Application.persistentDataPath + "/李佳/" + @"/TestXml.xml")) {
File.Move (A_dataPath, B_dataPath);
} else {
Debug.Log ("文件存在");
}
}
#endregion

 

}

xml常用方法

标签:

原文地址:http://www.cnblogs.com/ZeroMurder/p/5613134.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!