我有这个问题,我的文本文件没有完全加载到程序中,它跳过多个文本行,并从文件的中间开始。我如何修复它,以便它读取所有代码,而不仅仅是文本文件的中间? text file - 注意文件名对我来说叫做“hurcdata1”。
import java.util.Scanner;
import java.io.File;
import java.io.IOException;
public class Hurricanes2 {
public static void main(String[] args)throws IOException {
int [] year = new int [59];
String [] month = new String[59];
int [] pressure = new int [59];
int [] speed= new int [59];
String [] name= new String[59];
int [] x = new int [59];
double [] mp4= new double [59];
File fileName = new File("hurcdata1.txt");
Scanner inFile1 = new Scanner(fileName);
//INPUT - read data in from the file
int index = 0;
while (inFile1.hasNext()) {
year[index] = inFile1.nextInt();
month[index] = inFile1.next();
pressure[index] = inFile1.nextInt();
speed[index] = inFile1.nextInt();
name[index] = inFile1.next();
index++;
}
inFile1.close();
for( int z: year) {
System.out.printf("%5d %n",z);
}
}
}