0% found this document useful (0 votes)
63 views

Java Filestream HM2

The code tries to create a file named "a.txt" but does not actually create it, so the answer is B - false. The CharArrayReader class can be used to implement an input stream that uses a character array as the source. The program prints the number of bytes in the file "inputoutput.java". It uses the FileInputStream class to get an input stream from the file, and the available() method returns the number of bytes that can be read from the stream.

Uploaded by

Vinay Prakash
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views

Java Filestream HM2

The code tries to create a file named "a.txt" but does not actually create it, so the answer is B - false. The CharArrayReader class can be used to implement an input stream that uses a character array as the source. The program prints the number of bytes in the file "inputoutput.java". It uses the FileInputStream class to get an input stream from the file, and the available() method returns the number of bytes that can be read from the stream.

Uploaded by

Vinay Prakash
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 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

You might also like