using System.IO;
using UnityEngine;
using System.Collections;
public class Test : MonoBehaviour
{
// Use this for initialization
void Start()
{
//检测文件夹是否存在
if (!Directory.Exists(Application.dataPath + "/Test"))
{
Directory.CreateDirectory(Application.dataPath + "/Test");
}
else
{
Debug.Log("文件夹已经存在");
}
//创建文件
//File.Create(Application.dataPath + "/a.txt");
//移动文件
//File.Move(Application.dataPath + "/a.txt", Application.dataPath + "/Test/a.txt");
//检测文件是否存在
if (File.Exists(Application.dataPath + "/Test/a.txt"))
{
Debug.Log("文件存在");
FileInfo test = new FileInfo(Application.dataPath + "/Test/a.txt");
Debug.Log("文件创建时间是" + test.CreationTime.ToShortTimeString() + "/" + test.CreationTime.ToShortDateString());
}
else
{
Debug.Log("文件不存在");
}
//删除文件
//File.Delete(Application.dataPath + "/Test/a.txt");
//复制文件
File.Copy(Application.dataPath + "/Test/a.txt", Application.dataPath + "/a.txt");
//移动文件
//FileInfo temp = new FileInfo(Application.dataPath + "/a.txt");
//temp.MoveTo(Application.dataPath + "/Test/test.txt");
//实例化StreamWriter对象
StreamWriter sw = new StreamWriter(Application.dataPath + "/Test/a.txt", true);
sw.WriteLine("写入一行文字");
//关闭当前文件写入流
sw.Close();
}
}
C# System.IO命名空间
最新推荐文章于 2024-05-13 17:03:38 发布