现在的位置: 首页 > 综合 > 正文

Unity3D ReadFile

2013年10月03日 ⁄ 综合 ⁄ 共 788字 ⁄ 字号 评论关闭

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;
    }

   
}

抱歉!评论已关闭.