Hey there. Googled a bit to see if it was a common mistake / error but I found nothing.
Basically I just want to open a file and check its contents. Everything compiles without error but when the program runs it outputs nothing and throws the FileNotFound exception. Ironically it tells me it does not exist and gives me the complete path which I copy pasted in Windows explorer and it (WE) opened the file just file so it is not a question of the file not being in the wrong path or something. What could it be ?
Code:
using System;
using System.IO;
using System.Collections.Generic;
namespace Utils
{
class Logger {
private StreamWriter w;
public Logger() {
w = new StreamWriter("log.txt", true);
}
~Logger() {
w.Close();
}
public void ToLog(string msg) {
w.WriteLine(System.DateTime.Now.ToString() + ": " + msg);
}
}
class FSMachine {
private Dictionary<string, string> states;
private void ParseLine(string line) {
char[] delimitors = {' ', '='};
string[] tmp = line.Split(delimitors);
states[tmp[0]] = tmp[1];
}
public void CheckStatesFile(string path = "./config.ini") {
StreamReader r = new StreamReader(path);
while(r.Peek() >= 0) {
ParseLine(r.ReadLine());
}
}
public FSMachine() {
CheckStatesFile();
}
public bool IsStateSet(string key) {
return states.ContainsKey(key);
}
public string GetState(string key) {
return states[key];
}
}
}
namespace BLABLABLA {
class Program
{
public static void Main(string[] args)
{
Utils.FSMachine fs = new Utils.FSMachine();
if(fs.IsStateSet("abc")) Console.WriteLine(fs.GetState("abc"));
Console.Write("Press any key to continue . . . ");
Console.ReadKey(true);
}
}
}
By the way, yes I am a hardcore noob in C#. I base all my code on my C++ experience and googling to know what to use in C# so please forgive my code if it is really stupid in some points.