本文整理匯總了C#中System.IO.FileNotFoundException.Message屬性的典型用法代碼示例。如果您正苦於以下問題:C# FileNotFoundException.Message屬性的具體用法?C# FileNotFoundException.Message怎麽用?C# FileNotFoundException.Message使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。
在下文中一共展示了FileNotFoundException.Message屬性的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Main
//引入命名空間
using System;
using System.IO;
class Retry {
static void Main() {
StreamReader sr;
int attempts = 0;
int maxAttempts = 3;
GetFile:
Console.Write("\n[Attempt #{0}] Specify file " + "to open/read: ", attempts + 1);
string fileName = Console.ReadLine();
try {
sr = new StreamReader(fileName);
string s;
while (null != (s = sr.ReadLine())) {
Console.WriteLine(s);
}
sr.Close();
} catch (FileNotFoundException e) {
Console.WriteLine(e.Message);
if (++attempts < maxAttempts) {
Console.Write("Do you want to select another file: ");
string response = Console.ReadLine();
response = response.ToUpper();
if (response == "Y") goto GetFile;
} else {
Console.Write("You have exceeded the maximum retry limit ({0})", maxAttempts);
}
} catch (Exception e) {
Console.WriteLine(e.Message);
}
}
}