簡體   English   中英

讀取.csv文件時如何獲取編碼?

[英]How to get encoding when I read a .csv File?

作為標題,下面的代碼...

System.IO.FileInfo _fInfo;
OpenFileDialog openDlg = new OpenFileDialog();
openDlg.Filter = "Csv Files (.csv)|*.csv";
openDlg.FilterIndex = 1;
openDlg.Multiselect = false;
bool? userClickedOK = openDlg.ShowDialog();

if (userClickedOK == true)
{
    _fInfo = openDlg.File;
}
Stream fileStream = _fInfo.OpenRead();
using (System.IO.StreamReader reader = new StreamReader(fileStream))
{
    int lineNo = 1;
    while (!reader.EndOfStream)
    {
       reader.ReadLine();
    }
}

有什么辦法可以找到“ _fInfo”當前的編碼? PS:我使用了silverlight控制台(silverlight 2.0)。

首次讀取后,嘗試StreamReader.CurrentEncoding。 讀者將嘗試檢測編碼。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM