Вы находитесь на странице: 1из 3

K K Wagh Polytechnic, Nashik – 3

Question Bank : Java Programming (9113)


Class : TYIF (IF/V/C)
Chapter No. 06 Streams and File IO

Review Questions from previous MSBTE question papers:

1. Describe RandomAccessFile with operations.


2. What do you mean by a stream? State its applications.
3. Differentiate between byte streams and character streams.
4. How we will determine that file is a directory or not?
5. Give different forms of write ( ) method of OutputStream class.
6. Explain the differences between RandomAccessFile and FileReader.
7. Describe the process of garbage collection.
8. Describe following stream classes:
a. ByteArrayInputStream
b. PrintWriter
c. BufferedReader
d. FileOutputStream
9. Illustrate various ways of taking input from the keyboard.
10. What is serialization? Explain with suitable example.
11. Explain various constructors of File class.
12. Explain the hierarchy of stream classes in java.io package.
13. Distinguish between OutputStream and Writer class.
14. While reading a file, how do you determine that file pointer has reached
the end of file?
15. What are the advantages of random access file over sequential access
file?
16. Explain the meaning of various File class methods.
17. How the read ( ) method can be used in different ways? Explain.
18. What are the advantages provided by push back streams?
19. Explain various operations performed using FileInputStream and
FileOutputStream.
20. What are the drawbacks of using the byte stream classes?

Programming Exercises:

1. Copy the contents of one file into another and display the contents of
both files.
2. Accept the name of the file from command line and display its contents.
Also check whether that file is existed or not?
3. Convert the contents of a file into upper case.
4. Counts the numbers of lines of a file. Accept the file name from user.
5. Count total number of lower case characters of a file.

By Mr. Kute T. B. for (TYIF) 2008-2009 -1-


K K Wagh Polytechnic, Nashik – 3

6. Reverse the contents of the file using character streams.


7. A file contains 100 different characters. Use random access file to print
the alternate characters of that file.
8. Accept any character from user and insert that character at particular
position inside the file.
9. Merge the contents of two file and display it.
10. Delete the last line of the file “first.txt” and rename it with “first.java”.

Objective questions:

1. Which of the following is a legal way to construct a RandomAccessFile?


a) RandomAccessFile("data.txt", "r");
b) RandomAccessFile("r", "data.txt");
c) RandomAccessFile("data.txt", "read");
d) RandomAccessFile("read", "data.txt");

2. What is the permanent effect on the file system of writing data to a new
FileWriter("report.txt"), given the file “report.txt” already exists?
a) The data is appended to the file
b) The file is replaced with a new file
c) An exception is raised as the file already exists
d) The data is written to random locations within the file

3. Which of the following correctly illustrate how an InputStreamReader


can be created?
a) new InputStreamReader(new FileInputStream("data"));
b) new InputStreamReader(new FileReader("data"));
c) new InputStreamReader(new BufferedReader("data"));
d) new InputStreamReader("data");
e) new InputStreamReader(System.in);

4. Which of the following is the correct syntax for suggesting that the JVM
performs garbage collection?
a) System.free();
b) System.setGarbageCollection();
c) System.out.gc();
d) System.gc();

5. Which of the following will compile without error?


a) File f = new File("/","autoexec.bat");
b) DataInputStream d = new DataInputStream(System.in);
c) OutputStreamWriter o = new
OutputStreamWriter(System.out);
d) RandomAccessFile r = new RandomAccessFile("OutFile");

By Mr. Kute T. B. for (TYIF) 2008-2009 -2-


K K Wagh Polytechnic, Nashik – 3

6. Which of the following can we perform using the File class?


a) Change the current directory
b) Return the name of the parent directory
c) Delete a file
d) Find if a file contains text or binary information

7. The FileReader is subclass of which class?


a) InputStreamReader
b) BufferedReader
c) OutputStreamReader
d) CharArrayReader

8. Which interface the ObjectInputStream implements?


a) DataInput
b) InputStream
c) ObjectInput
d) DataInputs

9. Character stream counterpart of ByteArrayInputStream is ______?


a) ByteArrayReader
b) CharacterArrayReader
c) CharArrayReader
d) ArrayReader

10. What type of the value that readLine( ) returns ?


a) String
b) Char array
c) Byte array
d) String array

By Mr. Kute T. B. for (TYIF) 2008-2009 -3-

Вам также может понравиться