C# 在特殊文件夹C中添加文件夹#
我想将XML文件保存到此目录中。。。 C:\Users\john\AppData\Roaming\game\data.xml 我可以在这里导航。。。字符串路径=Environment.SpecialFolder.ApplicationData; 但是如何创建游戏文件夹并在此处保存data.xmlC# 在特殊文件夹C中添加文件夹#,c#,path,directory,special-folders,C#,Path,Directory,Special Folders,我想将XML文件保存到此目录中。。。 C:\Users\john\AppData\Roaming\game\data.xml 我可以在这里导航。。。字符串路径=Environment.SpecialFolder.ApplicationData; 但是如何创建游戏文件夹并在此处保存data.xml // Place this at the top of the file using System.IO; ... // Whatever you want to save. var contents
// Place this at the top of the file
using System.IO;
...
// Whatever you want to save.
var contents = "file contents";
// The app roaming path for your game directory.
var folder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "game");
// Creates the directory if it doesn't exist.
Directory.CreateDirectory(folder);
// The name of the file you want to save your contents in.
var file = Path.Combine(folder, "data.xml");
// Write the contents to the file.
File.WriteAllText(file, contents);
希望这能有所帮助。System.IO名称空间应该有您需要的一切。您尝试过什么?如果您在最近要求使用的
Environment.SpecialFolder.ApplicationData
中更新另一个版本中的代码,它很可能会正常工作。