#读取文件
string path = Application.streamingAssetsPath + "/AudioClip.txt";
FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.None);
StreamReader sr = new StreamReader(fs, System.Text.Encoding.Default);
if (null == sr) return;
string str = sr.ReadLine();
Debug.Log(str);
sr.Close();
#解析字符串
C# TryParse()用法
形式(以decimal为例): decimal.TryParse(str1,out num1)
功能:将str1转化成decimal类型,若转化成功,将值赋给num1,并返回true;
若转化失败,返回false。
#切割字符串与逐行读取文件
string[] lines = File.ReadAllLines(path, System.Text.Encoding.Default);
for (int i = 0; i < lines.Length; i++)
{
string[] splits = lines[i].Split(" ".ToCharArray());
}
在unity中使用代码读取文件
最新推荐文章于 2024-09-11 15:02:25 发布