Code
public class Login {
private String nickname;
private static String line;
public Login(String nickname) throws IOException {
this.nickname = nickname;
try {
Scanner input = new Scanner(new File(nickname + ".acc"));
while (input.hasNextLine()) {
line = input.nextLine();
}
input.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[]args) throws IOException {
new Login("example");
System.out.println(line);
}
}
I have a problem. If I use this code, my output will only say 34567. But my text file contains:
example
34567
How do I fix it, and is it possible that the scanner outputs both lines of text from the textfile to separate strings?