Java File Handling

Last Updated :
Discuss
Comments

Question 1

Which package contains the File class in Java?

  • java.io.file

  • java.file

  • java.io

  • java.nio.file

Question 2

Which Hibernate method is used to insert/save a new object into the database?

  • update()

  • merge()

  • save()

  • delete()

Question 3

In Hibernate, which method is used to remove an object (entity) from the database?

  • remove()

  • delete()

  • evict()

  • detach()

Question 4

What is the purpose of the createNewFile() method in the File class?

  • To open an existing file

  • To create a new directory

  • To create a new file if it does not exist

  • To delete a file

Question 5

What will file.exists() return if the file doesn’t exist?

  • true

  • false

  • null

  • Throws Exception

Question 6

Which of the following can read text from a file line-by-line in Java?

  • FileWriter

  • BufferedWriter

  • Scanner

  • PrintWriter

Question 7

What is the output of this code?

Java
File f = new File("demo.txt");
System.out.println(f.isDirectory());

Assume demo.txt is a file, not a folder.

  • true

  • false

  • null

  • Compilation Error

Question 8

Which method is used to get the size of a file in bytes?

  • getSize()

  • getLength()

  • length()

  • size()

Question 9

What does delete() method of the File class return when deletion fails?

  • Throws an exception

  • Returns false

  • Returns null

  • Returns the file name

Question 10

What is the correct way to create a directory in Java?

  • File.mkdir()

  • File.createDirectory()

  • File.createDir()

  • File.makeDirectory()

There are 12 questions to complete.

Take a part in the ongoing discussion