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

Unity3D ReadFile

2013-09-02 13:44 204 查看
using UnityEngine;

using System.Collections;

using System.IO;

using System;

public class Script_08_03 : MonoBehaviour

{

    void Start ()

    {

        ArrayList info = LoadFile(Application.dataPath,"FileName");

        foreach(string str in info)

        {

            Debug.Log(str);

        }

    }

    private ArrayList LoadFile(string path, string name)

    {

        // 使用流读取

        StreamReader sr = null;

        try

        {

            sr = File.OpenText(path + "//" +name);

        }

        catch(Exception _ex)

        {

            // 通过名称与路径均未找到问价返回空

            return null;

        }

        string line;

        ArrayList arrList = new ArrayList();

        while((line = sr.ReadLine()) != null)

        {

            // 逐行读取

            arrList.Add(line);

        }

        // 关闭流

        sr.Close();

        // 销毁流

        sr.Dispose();

        // 返回数据链表容器

        return arrList;

    }

   

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