G
Guest
I am seeing something I don't understand. I am creating a new file that does not exist. After instantiating StreamWriter passing the file name then FileInfo.Exists is true. Great. If I access FileInfo.Exists before the StreamWriter it is false. Great. Now if I access FileInfo.Exists before and after StreamWriter it always returns false. Why????
See comments in code
using System
using System.IO
class Bu
static void Main(
FileInfo afileinfo = new FileInfo("list.txt")
try
// if you uncomment the next lin
//bool b = afileinfo.Exists
// then Console.WriteLine prints "list.txt does NOT exist!
// even though the file exists
// Also, if you display afileinfo.Exists in the
// debug Locals window it does the same thing
StreamWriter asw = new StreamWriter("list.txt")
if ( afileinfo.Exists
Console.WriteLine("list.txt exists!")
els
Console.WriteLine("list.txt does NOT exist!")
asw.WriteLine("line")
asw.WriteLine("line")
asw.Close()
}
catch (IOException aexception)
System.Console.WriteLine(aexception.Message)
throw new NotSupportedException()
finally
afileinfo.Delete()
}
}
See comments in code
using System
using System.IO
class Bu
static void Main(
FileInfo afileinfo = new FileInfo("list.txt")
try
// if you uncomment the next lin
//bool b = afileinfo.Exists
// then Console.WriteLine prints "list.txt does NOT exist!
// even though the file exists
// Also, if you display afileinfo.Exists in the
// debug Locals window it does the same thing
StreamWriter asw = new StreamWriter("list.txt")
if ( afileinfo.Exists
Console.WriteLine("list.txt exists!")
els
Console.WriteLine("list.txt does NOT exist!")
asw.WriteLine("line")
asw.WriteLine("line")
asw.Close()
}
catch (IOException aexception)
System.Console.WriteLine(aexception.Message)
throw new NotSupportedException()
finally
afileinfo.Delete()
}
}