Assuming the file words.txt holds the following data: CS1 Java Illuminated what
ID: 3772060 • Letter: A
Question
Assuming the file words.txt holds the following data:
CS1 Java Illuminated
what is the output of this code sequence:
a. If the file is found?
b. If the file is not found?
Try
{
Scanner file = new Scanner ( new File( “words.txt”));
String result = “”;
While ( file.hasNext())
{
String s = file.next();
Result += s;
Result+= “ And”;
}
System.out.println ( “result is “+result);
File.close();
}
Catch ( FileNotFoundExcption fne)
{
System.out.println( “Unable to find words.txt”);
}
Catch (I0Exception ioe)
{
Ioe.printStackTrace();
}
Explanation / Answer
if file words.txt is found the output is
CS1 And Java And Illuminated
if file is not found, error message is displayed
Unable to find words.txt
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.