Java - Interview Questions and Answers for 'File handling' | Search Java Interview Question - javasearch.buggybread.com
Javasearch.buggybread.com
Share

Search Java Interview Questions


 2098 questions in repository.
 There are more than 200 unanswered questions.
Click here and help us by providing the answer.
Label / Company      Label / Company / Text

   



Interview Questions and Answers for 'File handling' - 8 question(s) found - Order By Newest

 Q1. Tell something about BufferedWriter ? What are flush() and close() used for ?
Admin
info@buggybread.com
Ans. A Buffer is a temporary storage area for data. The BufferedWriter class is an output stream.It is an abstract class that creates a buffered character-output stream.Flush() is used to clear all the data characters stored in the buffer and clear the buffer.Close() is used to closes the character output stream.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   java io   input output   file handling   file io   output stream   bufferedwriter   flush   close


 Q2. Have you ever tried compressing data using Java ?Core Java2016-11-15 11:10:29

Ans. Yes, we can use ZipInputStream class for compressing the FileInputstream object.

  Sample Code for ZipInputStream

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     file handling  FileInputstream  ZipInputStream


 Q3. Watching a directory for changes. Monitoring a directory.Core Java2016-11-15 11:13:30

Ans. http://www.logicbig.com/tutorials/core-java-tutorial/java-nio/java-watch-service/

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     file handling  monitoring directory


 Q4. Given two files with list of words, write a program to show the common words in both filesCore Java2017-01-28 11:31:20

 This question was recently asked at 'Google'.This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     file handling  file io  code  coding     Google


 Q5. What is the difference between

File f = new File("homexyz.txt");

and

File f = File.createTempFile("xyz",".txt","home"); ?
Core Java2017-01-23 12:31:28

Ans. First will not create physical file in storage whereas the second will.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     file handling  File.createTempFile      intermediate        rare


 Q6. Why is it important to close files and streams ?Core Java2017-02-03 12:19:22

Ans. Optimizing Resource utilization. When you open a file using any programming language , that is actually a request to operating system to access the file. When such a request is made , resources are allocated by the OS. When you gracefully close those files, those resources are set free.

In Java if you don’t close the streams and files, Garbage collection identifies the open files which have lost the reference and hence will close them.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     file handling


 Q7. Write a program that reads file using FileReader and BufferedReaderCore Java2016-08-18 10:18:03

Ans. File file = new File("/home/sample.txt");
FileReader fileReader = new FileReader(file);
BufferedReader bufferedReader = new BufferedReader(fileReader);
while ((line = bufferedReader.readLine()) != null) {
System.out.println(line);
}

  Sample Code for import java.io.BufferedReader; import java.io.File; import java.io.FileReader;

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     File handling  FileReader  BufferedReader


 Q8. Write a Program to read a file and then count number of words2017-08-24 14:28:29

Ans. public class CountwordsinFile {
   public static void main(String[] args) throws IOException{
      String line = null;
      
      File file = new File("C:Hello.txt");
      FileReader fileReader = new FileReader(file);
      
      BufferedReader bufferedReader = new BufferedReader(fileReader);
      
      int countWords = 0;
      
      do {
      
         line = bufferedReader.readLine();
       countWords += line.split(" ").length;
      
      } while(line != null);
   }
}

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     file handling  count number of words  code  coding




Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner



comments powered by Disqus
 

Help us and Others Improve. Please let us know the questions asked in any of your previous interview.

Any input from you will be highly appreciated and It will unlock the application for 10 more requests.

Company Name:
Questions Asked:
         

X Close this

X Close this

Help Us Improve.
Please share your
interview experience.

Company Name:   


Questions Asked: