파일을 읽고 특정 형식으로 결과를 인쇄하려고합니다. 인쇄 할 때마다 다른 모든 항목 만 인쇄합니다. while 루프에서는 if 문을 전환하고 0을 -1로 변경 한 다음 ++를 계산하려고 시도했지만 작동하지 않았습니다.java에서 파일을 읽지 만 출력은 다른 모든 행을 건너 뜁니다.
try
{
File f = new File("BaseballNames1.csv");
FileReader fr = new FileReader(f);
BufferedReader br = new BufferedReader(fr);
ArrayList<String> players = new ArrayList<String>();
String line;
int count = 0;
while((line = br.readLine()) != null)
{
if(count == 0)
{
count++;
continue;
}
players.add(br.readLine());
}
for(String p : players)
{
String[] player = new String[7];
player = p.split(",");
first = player[0].trim();
last = player[1].trim();
birthDay = Integer.parseInt(player[2].trim());
birthMonth = Integer.parseInt(player[3].trim());
birthYear = Integer.parseInt(player[4].trim());
weight = Integer.parseInt(player[5].trim());
height = Double.parseDouble(player[6].trim());
name = first + " " + last;
birthday = birthMonth + "/" + birthDay + "/" + birthYear;
System.out.println(name + "\t" + birthday + "\t" + weight + "\t" + height);
//System.out.printf("First & Last Name %3s Birthdate %3s Weight %3s Height\n", name, birthday, weight, height);
}
}
catch(Exception e)
{
e.getMessage();
}
방금 읽은 행을 추가하기 전에 br.readLine()을 두 번 호출합니다. 그래서 선수가되어야합니다. add (line); – Juniar