Ask 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.

C) An error message is issued.

D) An EOF value is returned.

+5
Answers (1)
  1. 30 December, 21:55
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers