public static StringBuilder odczyt(string nazwa)
{
FileStream plik;
StringBuilder dane = new StringBuilder("");
try
{
plik = new FileStream(nazwa,FileMode.Open);
}
catch(FileNotFoundException)
{
Console.WriteLine ("Brak pliku {0}", nazwa);
}
int w;
do
{
w = plik.ReadByte();
if(w != -1)
dane.Append((char)w);
}
while( (w > 0) );
plik.Close();
return dane;
}
}
Its my simple function, and it was working, but now i dont know how it has happend it dont.
Monodevelop say plik does not have assigned value?
Coudl someone explain why ?
You are assigning your
plikinside thetry catchblock, which means that if you throw an exception during the assignment then you’ll be trying to use it without having first assigned it. Move your code after thetry catchblock into the block thus: