您的位置:首页 > 移动开发 > Unity3D

Unity3D CreateFile

2013-09-02 13:24 113 查看
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();

    }

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Unity3D