using System.IO;
class Test
{
static void Main(string[] args)
{
string path = @"c:\MyTest.txt";
try
{
if (!File.Exists(path))
{
StreamWriter sw = File.CreateText(path);
sw.WriteLine("Hello");
sw.Close();
}
}
catch(Exception e)
{
Console.WriteLine(e.Message);
}
// Open the file to read from.
StreamReader sr = null;
try
{
sr = File.OpenText(path);
string s = "";
while ((s = sr.ReadLine()) != null)
{
Console.WriteLine(s);
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
sr.Close();
}
}
在XP的VS2008上运行是可以的,在WIN7的VS2008上运行不通过,求解释
异常是文件的访问被拒绝···