0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

ローカルCSVを読み込みDto作成

Posted at
package design.controller;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

public class TestYou {

	private void readLocalCsv() {
		try {
			// Fileル名称
			String fileName = "c:/csv/TestYou.csv";
			File file = new File(fileName);
			// File読み込み
			BufferedReader br = new BufferedReader(new FileReader(file));
			// Fileヘッダ
			boolean isHeader = true;
			//File行
			String line = null;
			// File行数
			Long lineCnt = 0L;
			// 1行ずつファイルを読み込み
			while((line = br.readLine()) != null) {
				// headerの場合読み飛ばし
				if(isHeader) {
					isHeader = false;
					continue;
				}
				lineCnt ++;
				// aa読み込んだ行をカンマで分割し配列に保持
				String[] readColumns = line.split(",",-1);
				System.out.println(readColumns.length);
				System.out.println(readColumns[0]);
			}
		} catch (FileNotFoundException e) {
			System.out.println("File Not Found");
		} catch (IOException e) {
			System.out.println("IOException");
		}
	}

}

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?