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;
}
}
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;
}
}
本文介绍了一个Unity脚本,用于从指定路径加载文件,并将每行内容读取到ArrayList中进行处理。示例展示了如何在Start()方法中调用此功能并打印加载的数据。
1万+

被折叠的 条评论
为什么被折叠?



