我在Visual Studio 2017中使用XNA Game 4.0项目,并且在编辑文件夹中的文件时遇到问题。
我在一个名为debuglog.txt
的文件夹中有一个名为Logs
的文件。
文件夹和文件已正确添加到项目中;它们都正确地出现在bin/x68/Debug
目录中(debuglog.txt
在Logs
,而Logs
在bin/x68/Debug
)。
但是,当我尝试在LoadContent
方法中编辑文件的内容时,如下所示:
public string fileName = @"Content\Logs\debuglog.txt";
...
protected override void LoadContent(){
//Only the relevant code is shown and this is guaranteed to run
using(StreamWriter writer = new StreamWriter(File.Open(fileName, FileMode.OpenOrCreate))){
writer.Write("Test");
}
}
该文件中没有“Test”。
我试图省略文件路径的Content
部分,但它也没有工作。
问:为什么没有写入文件?
你没有得到任何例外吗?然后我会怀疑相对路径写到另一个位置。你在磁盘上还有其他'debuglog.txt'吗?尝试在writer.Write上设置断点并检查stream / Name的值。它指向正确的路径吗?