[英]XNA Game Studio - Cannot edit files in project
I am using an XNA Game 4.0 project in Visual Studio 2017, and am having problems with editing a file within a folder. 我在Visual Studio 2017中使用XNA Game 4.0项目,并且在编辑文件夹中的文件时遇到问题。
I have a file called debuglog.txt
in a folder called Logs
. 我在名为
Logs
的文件夹中有一个名为debuglog.txt
的文件。
The folder and file were added to the project properly; 文件夹和文件已正确添加到项目中; they both appear in the
bin/x68/Debug
directory correctly ( debuglog.txt
is in Logs
, and Logs
is in bin/x68/Debug
). 它们都正确显示在
bin/x68/Debug
目录中( debuglog.txt
在Logs
,而Logs
在bin/x68/Debug
)。
However, when I try to edit the contents of the file in the LoadContent
method like so: 但是,当我尝试像这样在
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");
}
}
the file does not have "Test" in it. 该文件中没有“测试”。
I tried to leave out the Content
part of the file path, but it didn't work then either. 我试图忽略文件路径的“
Content
部分,但后来也没有用。
Q: Why is the file not being written to? 问:为什么未写入文件?
Are you not getting any exceptions? 你没有例外吗? Then I would suspect the relative path writing to another position.
然后我会怀疑相对路径写到了另一个位置。 Do you have any other 'debuglog.txt' on the disk?
磁盘上是否还有其他“ debuglog.txt”? Try setting a break-point on writer.Write and check value for stream/Name.
尝试在writer上设置一个断点。写入并检查流/名称的值。 Is it pointing to the correct path?
它指向正确的路径吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.