C#
//檢查檔案是否存在 if (!File.Exists(FilePath)) { MessageBox.Show("找不到檔案"); return; } StreamReader objReader = new StreamReader(FilePath); string sLine = ""; ArrayList arrText = new ArrayList(); do { sLine = objReader.ReadLine(); if (sLine != null) { arrText.Add(sLine); } } while (sLine != null); objReader.Close(); //把讀取檔案的結果放到ListBox,您也可以另做運用。 ListBox.Items.AddRange(arrText);
VB
'檢查檔案是否存在 If Not FileIO.FileSystem.FileExists(FilePath) Then MsgBox("找不到檔案") Return End If Dim objReader As New StreamReader(FilePath) Dim sLine As String = "" Dim arrText As New ArrayList() Do sLine = objReader.ReadLine() If Not sLine Is Nothing Then arrText.Add(sLine) End If Loop Until sLine Is Nothing objReader.Close() '把讀取檔案的結果放到ListBox,您也可以另做運用。 ListBox.Items.AddRange(arrText)
文章標籤
全站熱搜