4

所以我正在尝试编译一个小行星游戏。它几乎可以工作,所有文件都到位等等......

当它遇到此代码时,问题就来了。

FileStream myFileStream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read);
string myTempFile = @"F:\Documents\Junior School\Computer Programming (Java 1)\AsteroidsWithSound\AsteroidsWithSound\temp\mysound" + i.ToString() + ".wav";

它给了我一个错误/警告,不确定它到底叫什么,但它说

ArgumentException 未处理。空路径名是不合法的。

我已经在网上阅读了有关导致此问题的此类代码块,但始终找不到解决方案。任何帮助都是极好的。

编辑:文件名在这个块中定义。

string filename = this.Player.FileName;
this.Player.Open("");
File.Delete(filename);
this.isReady = true;
4

2 回答 2

10

这表明该filename变量引用了一个空字符串。

您还没有显示设置 的值的代码filename,但这是要查看的部分。

于 2010-10-19T18:54:13.513 回答
0

First of, try and see what you get when you put a Watch on filename, and break at the exception-throwing line. If it's empty, then find out when was it set to the empty string, if it's not empty, then something's very wrong here and it might be the result of another (evil) code piece somewhere.

Next, I'll suggest you use File.readXXXXX to read the file and not a new FileStream. The File class can handle the open-read-close procedure very nicely.

Hope it helps

于 2010-10-20T05:05:39.323 回答