filenames = Application.dataPath + @"\StreamingAssets\配置文件.txt"
多媒体项目中经常遇到需要加载配置文件的,这里我们使用readAllLines方法
public string ReadALine(string FileName, int linenumber) // 参数1:打开的文件(路径+文件命),参数2:读取的行数
{
string[] strs = File.ReadAllLines(FileName);//将filename路径的txt读取为string数组
if (linenumber == 0)
{
return "0";
}
else
{
return strs[linenumber - 1];
}
}
写入txt的方法 File.WriteAllLines (数组,路径)