Search Interview Questions | More than 3000 questions in repository. There are more than 900 unanswered questions. Click here and help us by providing the answer. Have a video suggestion. Click Correct / Improve and please let us know. |
|
| ||||
Core Java - Interview Questions and Answers for 'File handling' - 32 question(s) found - Order By Newest | ||||
| ||||
Ans. NullPointerException at line: "File file = new File("/folder", name);" | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   io   file   fileio   coding   code   file handling | ||||
| ||||
Ans. A Stream is an abstraction that either produces or consumes information. There are two types of Streams : Byte Streams: Provide a convenient means for handling input and output of bytes. Character Streams: Provide a convenient means for handling input & output of characters. Byte Streams classes: Are defined by using two abstract classes, namely InputStream and OutputStream. Character Streams classes: Are defined by using two abstract classes, namely Reader and Writer. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   file io   streams   byte stream   character stream  file handling Asked in 3 Companies | ||||
| ||||
Ans. It will create the file myfile.txt in the current directory. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   io   file   fileio   coding   code   file handling | ||||
| ||||
Ans. Yes. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   io   file   fileio   coding   code   objectoutputstream   fileoutputstream   yesno  file handling | ||||
| ||||
Ans. http://www.buggybread.com/2015/01/java-file-io-classes-and-interfaces.html | ||||
Sample Code for File | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   io   input output   file io  file handling | ||||
| ||||
Ans. import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.io.*; public class Common { public static void main(String ar[])throws Exception { File f=new File("a.txt"); File f1=new File("x.java"); System.out.println(f.exists()); FileInputStream fin = new FileInputStream(f); FileInputStream fin1 = new FileInputStream(f1); byte b[]=new byte[10000]; byte b1[]=new byte[10000]; fin.read(b); fin1.read(b1); String s1 = new String(b); String s2 =new String(b1); String words1[] = s1.trim().split(" "); String words2[] = s2.trim().split(" "); Listlist1 = new ArrayList<>(Arrays.asList(words1)); Listlist2 = new ArrayList<>(Arrays.asList(words2)); list1.retainAll(list2); System.out.println(list1); } } | ||||
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 Asked in 1 Companies | ||||
| ||||
Ans. File folder = new File(path); if(!folder.exists()){ try { folder.mkdir(); } catch (Exception e) {} } | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  code  coding  file handling basic | ||||
| ||||
Ans. BufferedWriter is temporary source for data storage.BufferedWriter is used to write character data to the file.Flush() is method available in B.W which ensures that all data items are written to file including last character.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 | ||||
| ||||
Ans. Scanner class introduced in Java 1.5 for reading Data Stream from the imput device. Previously we used to write code to read a input using DataInputStream. After reading the stream , we can convert into respective data type using in.next() as String ,in.nextInt() as integer, in.nextDouble() as Double etc | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   java5   scanner   file io   file input   data input stream  file handling basic | ||||
| ||||
Ans. The Reader/Writer class hierarchy is character-oriented, and the InputStream/OutputStream class hierarchy is byte-oriented | ||||
Sample Code for InputStream Sample Code for OutputStream | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   file io   streams   reader class   writer class   inputstream   outputstream   stream  file handling | ||||
| ||||
Ans. file.txtC:file.txtC:file.txt | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   io   file   fileio   coding   code   file handling | ||||
| ||||
Ans. NullPointerException at line:File file = new File("/folder", child); | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   io   file   fileio   coding   code   file handling | ||||
| ||||
Ans. ..file.txt C:WorkspaceProject..file.txt C:Workspacefile.txt | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   io   file   fileio   coding   code   file handling | ||||
| ||||
Ans. OutputStreamWriter | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   io   file   fileio   filewriter   outputstreamwriter  file handling | ||||
| ||||
Ans. FileReader | ||||
Sample Code for FileReader | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   io   file   fileio   filereader  file handling | ||||
| ||||
Ans. FileInputStream | ||||
Sample Code for FileInputStream | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   io   file   fileio   fileinputstream  file handling | ||||
| ||||
Ans. InputStream | ||||
Sample Code for InputStream | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   io   file   fileio   fileinputstream   inputstream  file handling | ||||
| ||||
Ans. c. File file = new File("../file.txt"); FileWriter fileWriter = new FileWriter(file); BufferedWriter bufferedOutputWriter = new BufferedWriter(fileWriter); | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   io   file   fileio   coding   code   filewriter   bufferedwriter   scjp   ocjp  file handling | ||||
| ||||
Ans. IOException | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   io   file   fileio   coding   code   exception   ioexception  file handling | ||||
| ||||
Ans. FileNotFoundException | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   io   file   fileio   coding   code   scjp   ocjp   filenotfoundexception   fileoutputstream  file handling | ||||
| ||||
Ans. Though we are trying to serialize BuggyBread1 object but we haven't declared the class to implement Serializable. This will throw java.io.NotSerializableException upon execution. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   io   file   fileio   coding   code   serialization   notserializableexception   exception   file handling | ||||
| ||||
Ans. No, It will throw java.io.NotSerializableException. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   io   file   fileio   coding   code   serialization   notserializableexception   exception   file handling | ||||
| ||||
Ans. Yes. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   io   file   fileio   coding   code   serialization   yesno  file handling | ||||
| ||||
Ans. Scanner is used for parsing tokens from the contents of the stream while BufferedReader just reads the stream. BufferedReader read files efficiently by using a buffer to avoid physical disk operations. Buffer size of Scanner is usually smaller than the Buffered Writer. BufferedReader is faster that Scanner as it just reads the Stream and doesn't Parse the tokens to read the stream into primitive data types. | ||||
Sample Code for Scanner Sample Code for BufferedReader | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   file io   input output   scanner   bufferedreader  file handling | ||||
| ||||
Ans. Buffer is cleared in 2 circumstances, i.e 1. naturally when the buffer is filled and 2. explicitly when the method flush is called ( for flushing the residual ) Ideally we just need to call flush once at the end of file writing so that the residual content should be dumped to file. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  BufferedWriter  Writer  PrintWriter  File io  flush  file handling | ||||
| ||||
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  file handling | ||||
| ||||
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 | ||||
| ||||
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  file handling intermediate   rare | ||||
| ||||
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 | ||||
| ||||
This question was recently asked at 'Amazon'.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 Asked in 1 Companies | ||||