在编写unity程序时,需要将配置文件中的内容需要读取加载到软件中,因此需要根据文件的相对路径来读取文件中的内容。代码如下:
public static string getFileContentByPath(string filePath)
{StreamReader streamReader = new StreamReader(filePath);string content = streamReader.ReadToEnd();return conten;
}
将加载显示的数据进行修改后,在重新保存到文件中,代码如下:
public static void saveFileContent(string filePath,string[] content)
{File.WriteAllLines(filePath,content);
}
字符串数组中存放,每一行需要保存的文件内容。