LoginSignup
0
0

More than 5 years have passed since last update.

CSVファイルを1行づつの読み込みます

Last updated at Posted at 2016-08-30

CSVのファイルをShift-JISで読み込みます。
今回の読み込み方法はStreamReaderを使って読み込みたいと思います。。
StreamReaderは特定のエンコードで文字を入力する際に使用します。
文字コードはCSVのためshit-JISになります。

StreamReader csvText = new StreamReader(csvPath, 
Encoding.GetEncoding("Shift-JIS")); //文字コードを設定してCSVファイルの読み込み
ArrayList lineCsv = new ArrayList();
string csvTextLine = csvText.ReadLine();
while (csvTextLine != null)
{
lineCsv.Add(csvTextLine);
csvTextLine = csvText.ReadLine();
}

ArrayListで動的な配列を行います。
ReadLineでテキストの1行づつ読み込みます。
それぞれを、再度配列"csvTextLine"に追加していきます。
そして、さらに動的な配列lineCsvに加えて行きます。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0