美文网首页
讀取文件

讀取文件

作者: 球球1104 | 来源:发表于2017-02-16 15:48 被阅读0次

    开启文件对话框:

        //初始化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();
    

    相关文章

      网友评论

          本文标题:讀取文件

          本文链接:https://www.haomeiwen.com/subject/kpfhwttx.html