I have to take this text file:
Ulric Schwartz [email protected] Fringilla Donec PC urna convallis erat
Jesse Conrad [email protected] Magna Praesent Interdum Incorporated et netus
et
Ethan Eaton [email protected] Sed Consequat Auctor Institute posuere
vulputate lacus
Griffin Stephenson [email protected] Purus Sapien Institute auctor non
feugiat
Alan Howell [email protected] Mi Limited non sollicitudin a
Sawyer Stokes [email protected] Ut Institute nibh Phasellus nulla
Nigel Sanford [email protected] 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);
}
}