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 (數組,路徑)