using UnityEngine;
using System.Collections;
using System.IO;
public class Script_08_02 : MonoBehaviour
{
void Start ()
{
Debug.Log(Application.dataPath);
CreateFile(Application.dataPath, "FileName","TestInfo0");
CreateFile(Application.dataPath, "FileName", "TestInfo1");
CreateFile(Application.dataPath, "FileName", "TestInfo2");
}
/// <summary>
/// 创建一个文件
/// </summary>
/// <param name="path">路径</param>
/// <param name="name">名称</param>
/// <param name="info">写入的内容</param>
void CreateFile(string path, string name, string info)
{
// 文件流信息
StreamWriter sw;
FileInfo t = new FileInfo(path + "//" + name);
if (!t.Exists)
{
// 如果文件不存在则创建
sw = t.CreateText();
}
else
{
// 如果文件存在,则打开该文件
sw = t.AppendText();
}
// 以行的形式写入信息
sw.WriteLine(info);
// 关闭流
sw.Close();
// 销毁流
sw.Dispose();
}
}
using System.Collections;
using System.IO;
public class Script_08_02 : MonoBehaviour
{
void Start ()
{
Debug.Log(Application.dataPath);
CreateFile(Application.dataPath, "FileName","TestInfo0");
CreateFile(Application.dataPath, "FileName", "TestInfo1");
CreateFile(Application.dataPath, "FileName", "TestInfo2");
}
/// <summary>
/// 创建一个文件
/// </summary>
/// <param name="path">路径</param>
/// <param name="name">名称</param>
/// <param name="info">写入的内容</param>
void CreateFile(string path, string name, string info)
{
// 文件流信息
StreamWriter sw;
FileInfo t = new FileInfo(path + "//" + name);
if (!t.Exists)
{
// 如果文件不存在则创建
sw = t.CreateText();
}
else
{
// 如果文件存在,则打开该文件
sw = t.AppendText();
}
// 以行的形式写入信息
sw.WriteLine(info);
// 关闭流
sw.Close();
// 销毁流
sw.Dispose();
}
}