There are quite a few things you need to look at here, but the compilation error you are probably getting relates to the line:
File[] fe = (new Directory(".")).GetFiles(cmdline[1]);
And tells you that you can't create an array of static objects.
The problem is that the File class is static - there is one and only one instance of it for the entire application, so you cannot under any circumstances create a File variable, and certainly not an array of them - because you can't get at the object to fill it with!
Butthere is a wider problem with this line: GetFiles is a static property of the Directory class, and it doesn't return File objects, it returns an array of strings. So what you actually should have said here is:
string[] fe = Directory.GetFiles(cmdline[1]);
But that isn't actually what you want to do either! There is a much, much easier way to achieve what you want:
if (!File.Exists(cmdline[1]))
{
Console.WriteLine(cmdline[1] + ": file not found");
return;
}
"sir can u edit the above code and update it please using if(!File.Exists(loadFille)"
Well...it's your homework...so I really shouldn't...
But, ok - if you can tell me exactly what is going on, and why I moved some of your code around!
public static void Main(string[] args)
{
String[] cmdline = Environment.GetCommandLineArgs();
Console.WriteLine("File Reader Using Stream Reader & File Stream \n");
if (cmdline.Length < 2)
{
Console.WriteLine("Usage: " + cmdline[0] + " <input file> ");
return;
}
string loadFile = cmdline[1];
if (!File.Exists(loadFile))
{
Console.WriteLine(loadFile + " : file not found");
return;
}
try
{
FileRead fr = new FileRead();
FileInfo fi = new FileInfo(loadFile);
fr.ReadFile(loadFile, (int) fi.Length);
}
catch (IOException e)
{
Console.WriteLine("I/O error occured" + e);
return;
}
}