这个问题已经在这里有一个答案:
- 扫描仪跳过从文件[复制]每秒线 5个回答
我的计划打印就行了所有数据,但只输出每隔一行。 我知道它有什么做的“nextLine”,但我找不到什么导致了问题。
import java.io.*;
import java.util.*;
public class hw2
{
public static void main (String[] args) throws Exception
{
String carrier;
int flights;
int lateflights;
int ratio;
String[][] flightData= new String [221][3];
String[] temp;
File file = new File ("delayed.csv");
Scanner csvScan = new Scanner(file);
int c = 0;
while ((csvScan.nextLine()) != null){
String s = csvScan.nextLine();
temp = s.split(",");
for(int i =0; i < temp.length ; i++)
System.out.println(temp[i]);
flightData[c][0] = temp[1];
flightData[c][1] = temp[6];
flightData[c][2] = temp[7];
c = c+1;
}
}
}