4. public static void main (String[] args) { try (FileInputStream fis = new FileInputStream ("test.dat");) { // any code written } catch (IOException ex) { System.out.Println("Something goes wrong"); } catch (FileNotFoundException ex) { System.out.Println("Can't find the file"); } } Hint: the above code will not run successfully, why? By using eclipse program find Answer:
Added by Jody C.
Close
Step 1
The main method is the entry point of the program. Show more…
Show all steps
Your feedback will help us improve your experience
Rabeya Zahid and 73 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
To avoid an IOException exception with files,you can either use a try...catch block or make sure there is a file before attempting to read characters from it.This can be done by: a. calling the File.Exists( ) method b. using a loop to cycle through the file structure c. throwing an exception d. including statements in a finally block e. placing a test loop in the Main( ) method
/** * Prompt the user to enter a filename, then use the provided * Scanner object to read the entire line of user input as * a String value. Use this value to create a new File object, * then use the exists() and isFile() methods to check that * the user-specified file is valid. If the file does not * exist or is not a file, display an error message and prompt * the user again. If the file is valid, return the File object * to the caller. * @param kbd Scanner object bound to System.in * @return Valid File object that represents the filename entered by the user. */ public static File getFile(Scanner kbd) {...}
Supreeta N.
Suppose you define a java class as follows: public class test { } in order to compile this program, the source code should be stored in a file named ________.
John B.
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
18,000,000+
Students on Numerade
Trusted by students at 8,000+ universities
Watch the video solution with this free unlock.
EMAIL
PASSWORD