Answer the question
In order to leave comments, you need to log in
Why does it not display the first line when reading from a file?
There is a file test.txt, it contains the words: First line, Second Line. Third Line (To column)
But when reading a file, it shows only Second Line and Third Line
package String;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws FileNotFoundException {
String separator = File.separator;
String path = "C:" + separator + "Users" + separator + "denis" + separator + "Desktop" + separator + "test.txt";
File file = new File(path);
Scanner scanner = new Scanner(file);
String input = scanner.nextLine();
while(scanner.hasNextLine()){
System.out.println(scanner.nextLine());
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question