Unit 6 Java Programmingg Question Answer - Copy - Copy-1
Unit 6 Java Programmingg Question Answer - Copy - Copy-1
Unit 6 Java Programmingg Question Answer - Copy - Copy-1
UNIT6
1 2M
Draw the hierarchy of stream
classes.
2M-
Correct
diagram
One
method
1M
try {
// create a writer for permFile
BufferedWriter out = new BufferedWriter(new FileWriter(permFile,
true));
// create a reader for tmpFile
BufferedReader in = new BufferedReader(new FileReader(tmpFile));
String str;
while ((str = in.readLine()) != null) {
out.write(str);
}
in.close();
out.close();
} catch (IOException e) {
}
}
}
17 Enlist types of Byte strem class and describe input stream class and 4M
output stream class
ByteStream classes are used to read bytes from the input stream and write
bytes to the output stream. In other words, we can say that ByteStream classes
read/write the data of 8-bits. We can store video, audio, characters, etc., by
using ByteStream classes. These classes are part of the java.io package.
The ByteStream classes are divided into two types of classes, i.e., InputStream
and OutputStream.
InputStream Class
The InputStream class provides methods to read bytes from a file, console or
memory. It is an abstract class and can't be instantiated; however, various
classes inherit the InputStream class and override its methods. The methods of
InputStream class are given in the following table.
OutputStream Class
The OutputStream is an abstract class that is used to write 8-bit bytes to the
stream. It is the superclass of all the output stream classes. This class can't be
instantiated; however, it is inherited by various subclasses
18 enlist any four methods of file input stream class and give syntax of any 4M
two methods
Syntax of methods
read ():
ch=fileInputStream.read();
Example of read()
1. import java.io.FileInputStream;
2. public class DataStreamExample {
3. public static void main(String args[]){
4. try{
5. FileInputStream fin=new FileInputStream("D:\\testout.txt");
6. int i=fin.read();
7. System.out.print((char)i);
8.
9. fin.close();
10. }catch(Exception e){System.out.println(e);}
11. }
12. }
close():
FileInputStream object( fin).close();
try {
input.skip(5);
int i = input.read();
while (i != -1) {
System.out.print((char) i);
i = input.read();
input.close();
catch (Exception e) {
e.getStackTrace();