using UnityEngine;
using System.Collections;
using System.IO;
using System;
public class ReadOrSaveFile : MonoBehaviour
{
//保存信息到文件
public void SaveContentToFile(string _Path,string _fileName, string _content)
{
//string fileName = "Text_" + DateTime.Now.ToString("yyyy_MM_dd_H_m_s") + ".txt"; 时间命名文件名
string directoryPath = _Path;
string filename = _fileName;
if (!Directory.Exists(directoryPath))
{
Directory.CreateDirectory(directoryPath);
}
StreamWriter sw = new StreamWriter(Path.Combine(directoryPath, _fileName));
sw.Write(_content);
sw.Flush(); //清楚缓存内容
sw.Close();
}
//截屏
public void captureScreenshot(string path)
{
string _path = Path.Combine(path, "GameLog_" + DateTime.Now.ToString("yyyy_MM_dd_H_m_s") + ".png");
Application.CaptureScreenshot(_path);
}
//读取文件中信息
public ArrayList GetContentInFile(string _Path, string _content)
{
ArrayList arrayList = new ArrayList();
StreamReader sr = null; //使用流的形式读取
sr = File.OpenText(_Path);
if (sr != null)
{
string str;
while ((str = sr.ReadLine())!= null)
{
arrayList.Add(str);
}
}
sr.Close(); //关闭流
sr.Dispose(); //销毁流
return arrayList;
}
}
Unity3d 读写txt
最新推荐文章于 2022-11-15 15:34:39 发布