Ask Question
25 October, 13:43

If a file is opened for reading and the file does not exist, what action is taken?

A) A new file is created.

B) A NULL value is returned.

C) An error message is issued.

D) An EOF value is returned.

+3
Answers (1)
  1. 25 October, 16:02
    0
    C) An error message is issued.

    Explanation:

    If we try to open a file for reading when that file does not exist, we will get an error message.

    For example, in Java we will encounter a FileNotFoundException as in the code below:

    try {

    FileInputStream fis = new FileInputStream ("myFile. txt");

    DataInputStream dis = new DataInputStream (fis);

    BufferedReader br = new BufferedReader (new InputStreamReader (dis));

    String str = null;

    while ((str = br. readLine ()) ! = null) {

    System. err. println (str);

    }

    } catch (FileNotFoundException e) {

    e. printStackTrace ();

    }

    If the file myFile. txt does not exist we can expect to see an exception stack trace corresponding to FileNotFoundException.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “If a file is opened for reading and the file does not exist, what action is taken? A) A new file is created. B) A NULL value is returned. ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers