Enter your keyword



In data processing, using an office metaphor, a file is a related collection of records. For example, you might put the records you have on each of your customers in a file. In turn, each record would consist of fields for individual data items, such as customer name, customer number, customer address, and so forth. By providing the same information in the same fields in each record (so that all records are consistent), your file will be easily accessible for analysis and manipulation by a computer program.


import java.io.File;

public class Main {
public static void main(String[] args) {
File file1 = new File("C:/File/demo1.txt");
File file2 = new File("C:/java/demo1.txt");
if(file1.compareTo(file2) == 0) {
System.out.println("Both paths are same!");
} else {
System.out.println("Paths are not same!");

Commonly asked interview questions on Constructors

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
Answer: C. Character Stream
Explanation: InputStream & OutputStream classes under byte stream they are not streams. Character Stream contains all the classes which can work with Unicode

2. Which of these class is used to read characters in a file?

[A] FileReader [B] FileWriter [C] FileInputStream [D] InputStreamReader
Answer: A. FileReader
Explanation: We can read characters in a file using FileReader class of Java.

3. Which of these method of FileReader class is used to read characters from a file?

[A] read() [B] scanf() [C] get() [D] getInteger()
Answer: A. read()

4. Which of these class can be used to implement input stream that uses a character array as the source?

[A] BufferedReader [B] FileReader [C] CharArrayReader [D] FileArrayReader
Answer: C. CharArrayReader
Explanation: CharArrayReader is an implementation of an input stream that uses character array as a source. Here array is the input source.

5. Which of these is a method to clear all the data present in output buffers?

Answer :[A] clear() [B] flush() [C] fflush() [D] close()
Answer: B. flush()
Explanation: none

Take Sample Test

Reference Books

1. Head First Java

No Comments

Add your review

Your email address will not be published.