Files and I/O


  1. What is the output of this program if input given is ‘prstquvwxyz’?
    import java.util.*;
    import java.io.*;
    public class Main
    {
    public static void main(String args[]) throws IOException
    {
    char c;
    BufferedReader obj = new BufferedReader(new InputStreamReader(System.in));
    do
    {
    c = (char) obj.read();
    System.out.print(c);
    } while(c != 'q');
    }
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    prstq


  1. Which of these class is used to read from byte array?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    ByteArrayInputStream



  1. Which of these classes are used by character streams for input and output operations?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    Character streams uses Writer and Reader classes for input & output operations.


  1. Which of these is used to perform all input & output operations in Java?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    Like in any other language, streams are used for input and output operations.



  1. What is the output of this program?
    import java.io.*;
    public class Chararrayinput_Example
    {
    public static void main(String[] args)
    {
    String object = "pqrst";
    int length = object.length();
    char p[] = new char[length];
    object.getChars(0, length, p, 0);
    CharArrayReader input1 = new CharArrayReader(p);
    CharArrayReader input2 = new CharArrayReader(p, 1, 4);
    int K;
    int L;
    try
    {
    while ((K = input1.read()) == (L = input2.read()))
    {
    System.out.print((char)K);
    }
    }
    catch (IOException e)
    {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: E

    No output is printed. CharArrayReader object input1 contains string “pqrst” whereas object input2 contains string “qrst”, when while((K=input1.read())==(L=input2.read())) is executed the starting character of each object is compared since they are unequal control comes out of loop and nothing is printed on the screen.