I have a C# Visual Studio 2008 Form which needs to read the contents of the relative file 'character/attacks.txt' File.Exists() returns false when I run it, even though I'm positive my directories are sorted. Code:
try
{
System.IO.StreamReader file = new System.IO.StreamReader("character/attacks.txt");
int counter = 0;
int numberOfLines = 0;
string line;
while ((line = file.ReadLine()) != null) { numberOfLines++; }
string[] attacks = new string[numberOfLines];
while ((line = file.ReadLine()) != null) { attacks[counter] = line; counter++; }
file.Close();
print(attacks.ToString());
}
catch (Exception ex)
{
print("ERROR"); print("Did you edit any files?"); print(ex.ToString());
}
Exception Error:
System.IO.FileNotFoundException: Could not find file 'D:\Users\Andrey\Desktop\Turn\character\attacks.txt'.
File name: 'D:\Users\Andrey\Desktop\Turn\character\attacks.txt'
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
at System.IO.StreamReader..ctor(String path, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize)
at System.IO.StreamReader..ctor(String path)
at TurnByTurn.Form1.button1_Click(Object sender, EventArgs e) in D:\Users\Andrey\Desktop\C#\TurnByTurn\TurnByTurn\Form1.cs:line 52
I'm porting my code from Python and never had any troubles with this. Thanks in advance!