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");
}
}
}
More than 1 year has passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme