My Report

Java I/O Test – 3


Correct Answer: 2 points | Wrong: -1 point
Grades: A* (100% score) | A (80%-99%) | B (60%-80%) | C (40%-60%) | D (0%-40%)
advertisement

1. Which of these class is used to read characters in a file?

2. Which of these class can be used to implement the input stream that uses a character array as the source?

3. Which of these method of FileReader class is used to read characters from a file?

4. What will be the output of the following Java program?

 
    import java.io.*;
    class Chararrayinput 
    {
        public static void main(String[] args) 
        {
	    String obj  = "abcdef";
            int length = obj.length();
            char c[] = new char[length];
            obj.getChars(0,length,c,0);
            CharArrayReader input1 = new CharArrayReader(c);
            CharArrayReader input2 = new CharArrayReader(c, 0, 3);
            int i;
            try 
            {
		while ((i = input1.read()) != -1) 
                {
                    System.out.print((char)i);
                }
       	    } 
            catch (IOException e) 
            {
	        // TODO Auto-generated catch block
                e.printStackTrace();
	    }
	}
    }

5. Which of these classes can return more than one character to be returned to input stream?

6. What will be the output of the following Java program?

 
    import java.io.*;
    class Chararrayinput 
    {
        public static void main(String[] args) 
        {
	    String obj  = "abcdefgh";
            int length = obj.length();
            char c[] = new char[length];
            obj.getChars(0, length, c, 0);
            CharArrayReader input1 = new CharArrayReader(c);
            CharArrayReader input2 = new CharArrayReader(c, 1, 4);
            int i;
            int j;
            try 
            {
		while ((i = input1.read()) == (j = input2.read())) 
                {
                    System.out.print((char)i);
                }
       	    } 
            catch (IOException e) 
            {
	        // TODO Auto-generated catch block
                e.printStackTrace();
	    }
	}
    }

7. Which of these stream contains the classes which can work on character stream?

8. What will be the output of the following Java program?

 
    import java.io.*;
    class Chararrayinput 
    {
        public static void main(String[] args) 
        {
	    String obj  = "abcdef";
            int length = obj.length();
            char c[] = new char[length];
            obj.getChars(0, length, c, 0);
            CharArrayReader input1 = new CharArrayReader(c);
            CharArrayReader input2 = new CharArrayReader(c, 0, 3);
            int i;
            try 
            {
		while ((i = input2.read()) != -1) 
                {
                    System.out.print((char)i);
                }
       	    } 
            catch (IOException e) 
            {
	        // TODO Auto-generated catch block
                e.printStackTrace();
	    }
	}
    }

 

Start practicing “1000 MCQs on Java”, and once you are ready, you can take tests on all topics by attempting our “Java Test Series”.

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.