使用FileInfo创建文件老是出错
如题,运行时老是提示“string”并不包含对“fi”的定义。
源代码如下:
using System;
using System.IO;
namespace SAMS.VisualCSharpUnleashed.Chapter7
{
class Class1
{
[STAThread]
static void Main(string[] aras)
{
//Create a new file
string filePath=@"D:\BegCSharp\test.txt";
FileInfo fi = new FileInfo(filePath);
//Print out the information if the file exists
if (fi.Exists)
{
Console.WriteLine("The file: {0} was last accessed on {1} "+
"and contains {2} bytes if data.",
filePath.fi.LastAccessTime,fi.Length);
}
else
Console.WriteLine("The file: {0} does not exist.",filePath);
Console.ReadLine();
}
}
}