Created
October 25, 2017 14:23
-
-
Save mrgarita/a5ddb21b1559b7cd166e136e46825cc9 to your computer and use it in GitHub Desktop.
C#:CSVファイルを読み込む
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
using System.Text; | |
namespace CSVファイルを読み込む | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
try | |
{ | |
// ファイルを読み取り形式で開く | |
StreamReader file = new StreamReader("tango.txt", Encoding.UTF8); | |
string line = null; | |
while ((line = file.ReadLine()) != null) // 1行ずつ読み込む | |
{ | |
string[] tango = line.Split(','); // カンマで区切って配列に格納 | |
Console.WriteLine(tango[0] + " " + tango[1]); | |
} | |
file.Close(); | |
} | |
catch (Exception e) | |
{ | |
Console.WriteLine(e.Message); // エラーメッセージを表示 | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment