Hello experts. I need some urgently!! this is the problem:
design and implement a program that creates an exception class called StringTooLongException designed to be thrown wheb a string is discovered that has too many characters in it.
In the main driver of the program, ask the user for a file name. The file is expected to contain data values(strings). What can go wrong? There are two principal concerns: The file may not exist, and the file may have data in the wrong format. Handle the FileNotFoundException exception by printing an appropriate message and allowinf the user to re-enter a new file name as many times as necessary.don't be concerned about the data being in the wrong format .
Then, read strings from the file until the file end. If a string is read that has too manu characters(say 20) ,throw the StringTooLongException exception. Handle this exception by printing an appropriate, and then continues processing more strings. after processing the entire file , print "task completed" on the console screen.
This is what I have:
public class TestProgStringTooLongException
static Scanner console = new Scanner(System.in);
static final int maxStringSize = 20;
public static void main(String args)
done = false;
eof = false;
System.out.println(" Enter a file name :");
filename = console.next();
done = true;
Scanner inFile = new Scanner(new FileReader("J:\\InputString.txt"));
System.out.println( " The file name is : " + filename);
catch( FileNotFoundException fnfRef)
str = console.next();
System.out.println(" Exception " + fnfRef.toString()+ " "+ str);
I already have a series of string store in a file called J:\\InputString.txt
I don't know how to make the user put a file name and handle the file not found exception and how to make the user puta file as many as possible.