Skipping Blank Lines in text File
843789Jun 22 2009 — edited Jun 22 2009I am working on an assignment in which i have to read from a text file and store the strings individually. The problem i have is that the text file has blank line between each set of strings. So i figured to use "fin.nextLine();" to skip that blank line and continue with storing the values. but i get
"Exception in thread "main" java.util.NoSuchElementException: No line found
at java.util.Scanner.nextLine(Unknown Source)
at processmsg.ProcessMessages.choice1(ProcessMessages.java:68)
at processmsg.ProcessMessages.main(ProcessMessages.java:25)"
which is where the fin.nexLine() is at. How can i just skip that blank line?
System.out.println("Please enter the file location");
Scanner stdin = new Scanner(System.in);
String fileName = stdin.nextLine();
// read the information from the file
try {
Scanner fin = new Scanner(new File(fileName));
String tSendName = fin.nextLine();
while(tSendName != null)
{
String tRecieveName = fin.nextLine();
String tPhoneNumber = fin.nextLine();
String tDate = fin.nextLine();
String tTime = fin.nextLine();
String tStatus = fin.nextLine();
String tMessage = fin.nextLine();
PhoneMessage phonemessage = new PhoneMessage(tSendName, tRecieveName,
tPhoneNumber, tDate, tTime, tStatus, tMessage);
fin.nextLine();
tSendName = fin.nextLine();