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 substring method storing this substring in it’s own String variable.Hint: Last character in a String is stringName.length( ) – 1Step 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.InputAll 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); } } } }
Freebies just for you
We are available 24/7
We help you complete college assignments in under 24 hours.
Get help with essays, research papers, PowerPoint Presentations, reports, reviews, and projects at incredibly low prices.
Write a program named JavaOrNot
Custom Papers
We will write a custom paper for you at $15.50 $11/page
Free title page
Free reference page
Free formatting
Unlimited revisons
EssayTab is hands down the best essay writing service for college students. I was initially skeptical about the quality of a product that has such a low price point but I can tell you that it’s worth every penny! I’ve been using EssayTab for my essays in college as well as in grad school, and they always deliver excellent content.

College Student