讀取文件

开启文件对话框:

    //初始化OpenFile
        string strFilePath;
        OpenFileDialog ofd = new OpenFileDialog();
   //屬性的設定
        ofd.Filter = "Bios File(*.txt)|*.txt|(*.*)|*.*";
        ofd.RestoreDirectory = false;
        ofd.Multiselect = false;
        ofd.FileName = this.toolStripTextBox_Laster.Text;
   //開啓界面
        if (ofd.ShowDialog() == DialogResult.OK)
        {
           strFilePath = ofd.SafeFileName;
        }

打开文本读取端口:

    //導入文件且為繁體字體
        StreamReader inputInfor = new StreamReader(strFilePath, System.Text.Encoding.GetEncoding("Big5"));
    //讀取每一行的數據
        string inputInforLine = inputInfor.ReadLine();
        while (inputInforLine != null)
        {
       inputInforLine = inputInfor.ReadLine();
        }

关闭文本读取端口:

       inputInfor.Close();

你可能感兴趣的:(讀取文件)