0
我正在使用以下代码来读取位于我的根项目目录中的.txt
文件,但是,我一直遇到输出不包含整个文件的主体。我的代码如下:尝试使用扫描仪读取.txt文件时文本丢失
public void readFile() throws IOException {
int index = 0;
int indexT = 1;
File fileName = new File(file);
Scanner inFile = new Scanner(fileName);
while (inFile.hasNext()) {
String line = inFile.nextLine();
System.out.println(line);
if (indexT%3 == 0) {
fileList[index] = inFile.nextLine();
} else if (indexT == 1 || indexT == 4 || indexT == 7){
playList[index] = inFile.nextLine();
} else {
break;
}
index++;
indexT++;
}
inFile.close();
}
我已经经历过类似的问题,一直无法确定与我的代码问题。据我所知,它应该是完美的。所有帮助表示赞赏!