package controller;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import model.TestPointModel;
@Slf4j
public class Execute {
public static void main(String[] args) {
String line;
List<TestPointModel> list = new ArrayList<TestPointModel>();
try {
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("C:\TEMP\お試しデータ.csv"))); //1レコード5カラムで、カラム名なしのtsvデータ(90,80,70,60,50など)
while ((line = br.readLine()) != null) {
var csvDate = line.split(",");
log.debug("csv datta is" + csvDate);
TestPointModel tpm = new TestPointModel();
System.out.print(csvDate[0].getClass());
** tpm.setNationalLanguage(Integer.parseInt(csvDate[0]));
tpm.setMath(Integer.parseInt(csvDate[1]));
tpm.setSociety(Integer.parseInt(csvDate[2]));
tpm.setScience(Integer.parseInt(csvDate[3]));
tpm.setEnglish(Integer.parseInt(csvDate[4]));**
list.add(tpm);
}
list.forEach(e -> System.out.println());
} catch (IOException e) {
// TODO 自動生成された catch ブロック
e.printStackTrace();
}
}
}
package model;
import lombok.Data;
@Data
public class TestPointModel {
private int nationalLanguage;
private int math;
private int science;
private int society;
private int english;
}
しつもんはなんでしょうか
投稿者の最初の質問文です。
Integer.parseIntが数値なのに変換できない
package controller;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import model.TestPointModel;
@Slf4j
public class Execute {
public static void main(String[] args) {
String line;
List<TestPointModel> list = new ArrayList<TestPointModel>();
try {
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("C:\\TEMP\\お試しデータ.csv")));
while ((line = br.readLine()) != null) {
var csvDate = line.split(",");
log.debug("csv datta is" + csvDate);
TestPointModel tpm = new TestPointModel();
System.out.print(csvDate[0].getClass());
tpm.setNationalLanguage(Integer.parseInt(csvDate[0]));
tpm.setMath(Integer.parseInt(csvDate[1]));
tpm.setSociety(Integer.parseInt(csvDate[2]));
tpm.setScience(Integer.parseInt(csvDate[3]));
tpm.setEnglish(Integer.parseInt(csvDate[4]));
list.add(tpm);
}
list.forEach(e -> System.out.println());
} catch (IOException e) {
// TODO 自動生成された catch ブロック
e.printStackTrace();
}
}
}
------------------------------------------------------------------------
package model;
import lombok.Data;
@Data
public class TestPointModel {
private double nationalLanguage;
private int nationalLanguage;
private int math;
private int science;
private int society;
private int english;
}
あなたの回答
tips
プレビュー