这是我做的创建和我的文件中写道:C#文件处理 - 创建一个文件,并打开
Create_Directory = @"" + path;
Create_Name = file_name;
private void Create_File(string Create_Directory, string Create_Name)
{
string pathString = Create_Directory;
if (!System.IO.Directory.Exists(pathString)) { System.IO.Directory.CreateDirectory(pathString); }
string fileName = Create_Name + ".txt";
pathString = System.IO.Path.Combine(pathString, fileName);
if (!System.IO.File.Exists(pathString)) { System.IO.File.Create(pathString); }
///ERROR BE HERE:
System.IO.StreamWriter file = new System.IO.StreamWriter(pathString);
file.WriteLine(Some_Method(MP.Mwidth, MP.Mheight, MP.Mtype, ""));
file.Close();
}
这里的问题,我已经奋战了整整一天,之后我写文件创造它。所以,我的程序创建一个文件就好了,然后写入之前给出了一个错误:
“类型‘System.IO.IOException’未处理的异常出现在mscorlib.dll”
“附加信息:进程无法访问文件'D:\ Projects \ Project 15 \ Project 15 \ world \ world maps \ A.txt',因为它正在被另一个进程使用。“有趣的是,当我再次运行程序并尝试创建一个已经存在的文件时,就像你看到的那样,它跳过了文件创建,写入和工作正常,我真的希望我的程序创建文件和写入,而不必重新运行它...我在这里没有看到什么? :S
我可以在这里看到很多有用的建议,我会尽力它出来了,我认为这会做:) – 2013-03-19 00:30:38
一个问题,但如果我的文件已经存在,会发生什么,我试图做出另一个同名的? 编辑:我发现了,它只是重写它,幸运的是我已经设法将我的旧代码与你融合在一起,并找到了适合我的东西,谢谢大家:D – 2013-03-19 00:34:59