scanner doesnt seem to work if number of lines aren't even..why?
im making a simple program (fooling around with java) and i tried uploading a file that have an uneven amount of lines. There's a error at the end of the program.. I post code + my txt file..any comments would be appreciated..
import javax.swing.*;
import java.util.*;
import java.io.*;
publicclass TestOnThursday{
publicstaticvoid main (String [] args)throws IOException{
JFileChooser jfc =new JFileChooser();
jfc.showOpenDialog(null);// opens the chooser
String file = jfc.getSelectedFile().getAbsolutePath();
Scanner sc =new Scanner(new File(file));
String eggs = sc.nextLine();
System.out.println(eggs);
while (sc.hasNext()){
String cheese = sc.nextLine();
String ham = sc.nextLine();
System.out.println(cheese);
System.out.println(ham);
}
System.out.println("end of file");
}
}
txt file(dont ask why I put such randomness..i have a test in about 2 days and i need to get ansome grade)
handsinmypockethandsinmypockethandsinmypocket
iam
thesmartest
kid
in
the
world
yay!!!!!!

