Sie sind auf Seite 1von 16

TAKE_HOME_TASK-2

FILE STREAMS
1.
Find output:
try{
File f = new File("a.txt");
}catch(Exception e){
}catch(IOException io){
}
Is this code create new file name a.txt ?
A.true
B.false
C.Compilation Error
D.None of these
2
Which of these classes defined in java.io and used for file-
handling are abstract?
A. InputStream
B. PrintStream
C. Reader
D. FileInputStream
E. FileWriter
• A.Only A
• B.Only C
• C.A and C
• D.B and D
3.
What is the output of this program?
import java.io.*;
class filesinputoutput {
public static void main(String args[]) {
InputStream obj = new FileInputStream("inputoutput.java");
System.out.print(obj.available());
}
}
Note: inputoutput.java is stored in the disk.
a) true
b) false
c) prints number of bytes in file
d) prints number of characters in the file
4.

• Which of these class can be used to implement


input stream that uses a character array as the
source?
a) BufferedReader
b) FileReader
c) CharArrayReader
d) FileArrayReader
5.
What is the output of this program?
import java.io.*;
class filesinputoutput {
public static void main(String args[]) {
InputStream obj = new FileInputStream("inputoutput.java");
System.out.print(obj.available());
}
}
Note: inputoutput.java is stored in the disk.
a) true
b) false
c) prints number of bytes in file
d) prints number of characters in the fileWhat is the output of this program?

import java.io.*;
6.

• WAP to count number of character and digits in


file”Student.txt”.
7.

• Write a program that reads a file name from the


user then displays information about whether the
file exists, whether the file is readable, whether the
file is writable, the type of file and the length of the
file in bytes.
8.

• Write a program that reads data entered by the


user and writes each line string into a binary file.
Display the sizes of the binary file.
9.

• Write a program to create a file named Test.txt if it


does not exist. Append new data to it if it already
exists. Write 100 integers created randomly into
the file using text I/O. Integers should be separated
by a space.
10.

• Create a class Student with attributes name,


roll_no, section and address. Write a test program
to implement Student class and store information
of student in file “Student.txt”.
11.

• Which of these stream contains the classes which


can work on character stream?
a) InputStream
b) OutputStream
c) Character Stream
d) All of the mentioned
12.

• Which of these class is used to read characters in a


file?
a) FileReader
b) FileWriter
c) FileInputStream
d) InputStreamReader
13.

• Which of these method of FileReader class is used


to read characters from a file?
a) read()
b) scanf()
c) get()
d) getInteger()
14

• Which of these values is returned by read() method


is end of file (EOF) is encountered?
a) 0
b) 1
c) -1
d) Null
15.

• Which of these exception is thrown by close() and


read() methods?
a) IOException
b) FileException
c) FileNotFoundException
d) FileInputOutputException

Das könnte Ihnen auch gefallen