在編寫unity程序時,需要將配置文件中的內容需要讀取加載到軟件中,因此需要根據(jù)文件的相對路徑來讀取文件中的內容。代碼如下:
public static string getFileContentByPath(string filePath)
{
StreamReader streamReader = new StreamReader(filePath);
string content = streamReader.ReadToEnd();
return conten;
}
將加載顯示的數(shù)據(jù)進行修改后,在重新保存到文件中,代碼如下:文章來源:http://www.zghlxwxcb.cn/news/detail-634347.html
public static void saveFileContent(string filePath,string[] content)
{
File.WriteAllLines(filePath,content);
}
字符串數(shù)組中存放,每一行需要保存的文件內容。文章來源地址http://www.zghlxwxcb.cn/news/detail-634347.html
到了這里,關于C#讀取加載文件中的內容并修改保存的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!