Java File Input and Output Questions and Answers
1. Which of these stream contains the classes which can work on character stream?
Loading...
2. Which of these class is used to read characters in a file?
Loading...
3. Which of these method of FileReader class is used to read characters from a file?
Loading...
4. Which of these class can be used to implement input stream that uses a character array as the source?
Loading...
5. Which of these is a method to clear all the data present in output buffers?
Loading...
6. Which of these classes can return more than one character to be returned to input stream?
Loading...
7. 7. What is the output of this program?
Note: inputoutput.java is stored in the disk.
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.
Loading...
8. What is the output of this 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();
}
}
}
Loading...
9. What is the output of this 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();
}
}
}
Loading...
10. What is the output of this 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();
}
}
}
Loading...
Are these questions helpful for you?
Related Quizzes
- Introduction To Java
- Java Network Programming
- Java File Input Output
- Java Socket Programming
- Java Data Types
- Java Operators
- Java Strings
- Java Arrays
- Java Package And Interface
- java.lang Package
- Java Swings
- Java Applets
- Java Exception Handling
- JSP And Servlet
- Struts And Hibernate
- Java Session
- JDBC
- Java Classes And Methods
- Java Generics
- Java Multithreading
Comments: (Your feedback is valuable to us)