if語句能檢查錯誤
處理異常和錯誤>finally塊的用途
當打開文件
代碼
using System;
using System
using System
using System
namespace FinallyDemo
{
class Program
{
static void Main(string[] args)
{
const string filePath = @
FileStream fs=null;
try
{
Console
fs = new FileStream(filePath
byte[] bytes = Encoding
//向流中寫入指定的字節數組
fs
//將緩沖區的內容存儲到媒介並清除緩沖區
fs
//將流指針移到開頭
fs
byte[] bytes
//從
fs
string str = Encoding
Console
}
catch (IOException ex)
{
Console
}
finally
{
Console
if (fs != null)
{
fs
}
Console
}
}
}
}
From:http://tw.wingwit.com/Article/program/net/201311/11798.html