1 The following pseudocode represents the procedure for read

(1)      The following pseudocode represents the procedure for reading from a sequential file.

                        open a stream  

                        while more information

                        read information

                        close the stream

            (a)     True        (b)     False

(2)      The try - catch block is designed to enable the programmer to detect and respond to exception errors.           

            (a)     True        (b)     False

(3)      A sequential file can be sorted by placing its data into an array, sorting the array, and     then writing the ordered data into a file.

            (a)     True        (b)     False

(4)      A control break is a temporary break from the flow of the logic of a program.

            (a)     True        (b)     False

(5)      Opening a file for output means that __________ .

            (a)     data may be stored onto the disk.

            (b)     data may be read from the disk.

            (c)     anything that appears as output on the screen is written to the disk.

(d)     data may be read from and stored onto the disk.

(6)      When a file is opened in the append mode, data written to the file replaces the data         already there.  

            (a)     True        (b)     False

(7)      Which of the following statements is used when you want to add data to the end of an existing sequential file?

            (a)     FileWriter in = new FileWriter(outputFile);

            (b)     FileReader in = new FileWriter(outputFile, true);

            (c)     FileReader out = new FileWriter(outputFile);

            (d)     FileWriter out = new FileWriter(outputFile, true);

(8)      When an existing file is opened for output, and not append, new data values are added at the end of the existing file.

            (a)     True        (b)     False

(9)      If a sequential file is opened for input, then this allows data to be placed into the file by the Java application.

            (a)     True        (b)     False

(10)    Which of the terms in the following line of code are named variables that could be          replaced as long as all other references were also updated?

                        FileReader in = new FileReader(inFile);

            (a) inFile     (b) in              (c) new                 (d) File         (e) FileReader

Considering the following class file, answer each of the questions given below.

import java.io.*; import java.io.FileReader;

import java.io.FileWriter;

public class ReadWrite {

public static void main(String[] args) throws IOException {

   

    File inputFile = new File(\"inData.txt\");

    File outputFile = new File(\"outData.txt\");

    FileReader in = new FileReader(inputFile);

    FileWriter out = new FileWriter(outputFile, true);

    int c;

    while ((c = in.read()) != -1)

      out.write(c);

    in.close();

    out.close();

}

     }

(11)    in is a FileWriter object.                                                  (a) True (b) False

(12)    out is a FileReader object.                                                            (a) True (b) False

(13)    inputFile is a File object associated with outData.txt .          (a) True (b) False

(14)    outputFile is a File object linked with inData.txt .   (a) True (b) False

(15)    out.close() is outside the block of the while loop.                      (a) True (b) False

(16)    in.close() is inside the block of the while loop.              (a) True (b) False

(17)    The while loop is used to both read from and write to the file. (a) True (b) False

(18)    (c = in.read()) != -1 is true when data can still be read. (a) True (b) False

(19)    The loop condition is false when the end of file marker is reached.          (a) True (b) False

(20)    FileWriter(outputFile, true) allows for appending.            (a) True (b) False

           

import java.io.*; import java.io.FileReader;

import java.io.FileWriter;

public class ReadWrite {

public static void main(String[] args) throws IOException {

   

    File inputFile = new File(\"inData.txt\");

    File outputFile = new File(\"outData.txt\");

    FileReader in = new FileReader(inputFile);

    FileWriter out = new FileWriter(outputFile, true);

    int c;

    while ((c = in.read()) != -1)

      out.write(c);

    in.close();

    out.close();

}

     }

Solution

Hi, I have answered first 8 questions.

Please repost other questions in separate post.


First lets see about Sequential File:
A sequential file is one that contains and stores data in chronological order. The data itself may be ordered or unordered within the file. Unlike a random-access file, sequential files must be read from the beginning, up to the location of the desired data. Sequential files are often stored on sequential access devices, like a magnetic tape.

1)
   A) True : read from begining from a sequential file

2)
   a) True : we put all error pron code in try block and
               when an exception is thrown it can be catched in \'catch\' block

3)
   a) True
4)
   a) True
       Base on some condition we can break current flow

5)
   (a) data may be stored onto the disk.

6)
   b) False
7)
   (d) FileWriter out = new FileWriter(outputFile, true);
8)
   b) False : old data are erased

(1) The following pseudocode represents the procedure for reading from a sequential file. open a stream while more information read information close the stream
(1) The following pseudocode represents the procedure for reading from a sequential file. open a stream while more information read information close the stream
(1) The following pseudocode represents the procedure for reading from a sequential file. open a stream while more information read information close the stream

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site