2011-05-22 57 views
0

Hallo There was hopng我可以要求一些建議。 這將是從textFile中讀取數據並將其添加到checkedListBox的最佳方式?從文本文件讀取數據到CheckedListBox

這樣的事情,雖然這不能正常工作。

FileStream fs = new FileStream("../../Features.txt", FileMode.Open, FileAccess.Read); 
      BufferedStream bs = new BufferedStream(fs); 
      fs.Close(); 

      StreamReader sr = new StreamReader("../../Features.txt"); 


      chkFeatures.Items.Add(sr.ReadToEnd()); 
      sr.Close(); 

問候 阿里安

回答

4

這裏是另一種方式:

string filePath = @"C:\test.txt"; 
if (System.IO.File.Exists(filePath)) 
    checkedListBox1.Items.AddRange(System.IO.File.ReadAllLines(filePath));