I have to take this text file:
Ulric Schwartz ullamcorper@Quisque.ca Fringilla Donec PC urna convallis erat
Jesse Conrad Nunc@eunulla.edu Magna Praesent Interdum Incorporated et netus
et
Ethan Eaton cursus@Nullam.co.uk Sed Consequat Auctor Institute posuere
vulputate lacus
Griffin Stephenson habitant@mattis.com Purus Sapien Institute auctor non
feugiat
Alan Howell lorem@penatibusetmagnis.com Mi Limited non sollicitudin a
Sawyer Stokes ornare@utmiDuis.com Ut Institute nibh Phasellus nulla
Nigel Sanford adipiscing@euerat.org Lacus Varius Corp Integer vitae nibh
and scan it for the email addresses, meaning an @ followed by atleast three characters, a period, and atleast two more characters. I understand how to scan the file:
while(fscan.hasNext())
{
//scan for emails goes in here
}
but I'm not sure how to scan for the email. This is what I have:
import java.io.*;
import java.util.Scanner;
public class lab11_emena {
public static void main(String[] args)
{
Scanner cscan = new Scanner(System.in);
System.out.println("Please enter the file name.");
String filename = " ";
filename= cscan.nextLine();
File inFile = new File(filename);
if(!inFile.exists())
{
System.out.println("File " + filename + " does not exist.");
System.exit(0);
}
Scanner fscan = new Scanner(inFile);//I am getting an error
here? Saying inFile was thrown
System.out.println("Opened file " + filename);
}
}