我无法弄清楚如何让控制台错误检查用户输入,然后打开请求的文件。有人能告诉我我做错了什么吗?C#打开带有错误信息的变量文件
这是我目前的程序。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
while (true)
{
Console.WriteLine(">Enter File to open.");//Prompt user for file name
try
{
if (!File.Exists(Console.ReadLine()))
throw new FileNotFoundException();//Check for errors
}
catch (FileNotFoundException)
{
Console.WriteLine("You stuffed up!"); //Display error message
}
}
System.Diagnostics.Process.Start(@Console.ReadLine()); //set valid reply response
Console.ReadLine();
}
}
}
你有一个无限循环,而(真){}这将永远不会结束,无论你输入给。代码System.Diagnostics.Process.Start(@ Console.ReadLine());无法达到。如果找到该文件,则可以打开该循环。 – keerthee