Even complicated and confusing topics will be easily developed and covered if you request our help writing an essay. Place an order today!

We will write a program named JavaOrNot.java to test that all files in our current directory have a .java extension. Any filename that does NOT have a .java extension will be logged in an external file. Step 1: Create an exception class called NotJavaException, designed to be thrown when a filename NOT ending in .java is encountered during processing. If a filename is encountered that doesn't fit that description (last 5 characters do not equal ".java"), the exception is thrown.

Note: First you want to check If the filename is greater than 5  then grab the last 5 characters using String's substringmethod storing this substring in it's own String variable.

Hint:Last character in a String is stringName.length( ) - 1

Step 2:catch and handle the exception if it is thrown.  Handle the exception (inside the catch) by printing the filename (really just a String) to an external file named nonJava.txt  

Note: You will need an outer try/catch to handle the opening of the external file.

Step 3:See driver program below to test the exception.Run your program in a directory with some .java files and some non-.java files (example: testit.txt is non-.java file)

Note:add the code for writing out to a file last.  For debugging, have your output go to the console so you can see what is happening within your program.Warning: Don't forget to close() file so output is flushed. NO need for a finally clause.

Input

All input comes from the files in the current directory. Here is the code to read files from the current directory ".":

import java.io.*; public class JavaOrNot{ public static void main(String [] args) { File folder = new File("."); //dot is current directory File[] listOfFiles = folder.listFiles(); //we now have array of File objects String name = ""; for (File file : listOfFiles) { #check it's a file not subdirectory if (file.isFile()) { name = file.getName(); //each file name is a String System.out.println(name); } } } }

testimonials icon
6-Ten is a convenience Store chain (franchise) is re-thinking how it will operate in the near future. It is currently h...
testimonials icon
 Purpose: In the first assignment, students are given a scenario in which the shipping manager who has worked for...
testimonials icon
Maisha marefu! Afya! Vifijo :)...
testimonials icon
COO’s assertion that EMR technology is not critical for the health care organizationYour manager has asked you to help to prepare a response to t...
testimonials icon
Surname1NameInstructorCourseDatePros and Cons of Making an Official Diagnosis and Labeling a PersonDiagnosis involves identification of the nature an...
testimonials icon
Insert surname1NameProfessorCourseDateDiscrimination in clothing storesThe discrimination that is being experienced in clothing stores is brought abo...
Calculate Price

When you use PaperHelp, you save one valuable — TIME

You can spend it for more important things than paper writing.

Approx. price
$65
Order a paper. Study better. Sleep tight. Calculate Price!
Created with Sketch.
Calculate Price
Approx. price
$65