# Java File Input and Output Questions and Answers

Here are the Java File Input and Output Interview Questions which can be helpful for cracking the Java interview in various companies.
1. 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
2. Which of these class is used to read characters in a file?
[B] FileWriter
[C] FileInputStream
3. Which of these method of FileReader class is used to read characters from a file?
[B] scanf()
[C] get()
[D] getInteger()
4. Which of these class can be used to implement input stream that uses a character array as the source?
5. Which of these is a method to clear all the data present in output buffers?
[A] clear()
[B] flush()
[C] fflush()
[D] close()
6. Which of these classes can return more than one character to be returned to input stream?

[B] Bufferedwriter
7. 7. 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
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);
int i;
try {
while ((i = input1.read()) != -1) {
System.out.print((char)i);
}
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
``````
[A] abc
[B] abcd
[C] abcde
[D] abcdef
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);
int i;
try {
while ((i = input2.read()) != -1) {
System.out.print((char)i);
}
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
``````
[A] abc
[B] abcd
[C] abcde
[D] abcdef
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);
int i;
int j;
try {
System.out.print((char)i);
}
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
``````
[A] abc
[B] abcd
[C] abcde
[D] None of the mentioned
{"ft_lang_label":"__label__en","ft_lang_prob":0.6028936,"math_prob":0.78610224,"size":3001,"snap":"2022-05-2022-21","text_gpt3_token_len":737,"char_repetition_ratio":0.14147481,"word_repetition_ratio":0.40860215,"special_character_ratio":0.28423858,"punctuation_ratio":0.24027073,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9756223,"pos_list":[0,1,2],"im_url_duplicate_count":[null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-05-28T13:52:38Z\",\"WARC-Record-ID\":\"<urn:uuid:0210f552-d579-49d6-9b7c-2298416dbc4a>\",\"Content-Length\":\"85415\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:01bab379-5055-44fe-865a-86fd1e861d23>\",\"WARC-Concurrent-To\":\"<urn:uuid:ccdc1191-63dc-40a2-a371-45813b2720cc>\",\"WARC-IP-Address\":\"165.22.216.48\",\"WARC-Target-URI\":\"https://www.eduzip.com/java-programming/java-file-inputoutput.html\",\"WARC-Payload-Digest\":\"sha1:NNUFXP54VYN7AJYONBQ5GGAWCZD576QC\",\"WARC-Block-Digest\":\"sha1:UCIOAIIISRXNF3J2ZN3EYQYN56DW4XHC\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-21/CC-MAIN-2022-21_segments_1652663016853.88_warc_CC-MAIN-20220528123744-20220528153744-00619.warc.gz\"}"}