Java File Handling

Last Updated :
Discuss
Comments

Question 1

Which package contains the File class in Java?

  • A

    java.io.file

  • B

    java.file

  • C

    java.io

  • D

    java.nio.file

Question 2

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

  • A

    update()

  • B

    merge()

  • C

    save()

  • D

    delete()

Question 3

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

  • A

    remove()

  • B

    delete()

  • C

    evict()

  • D

    detach()

Question 4

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

  • A

    To open an existing file

  • B

    To create a new directory

  • C

    To create a new file if it does not exist

  • D

    To delete a file

Question 5

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

  • A

    true

  • B

    false

  • C

    null

  • D

    Throws Exception

Question 6

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

  • A

    FileWriter

  • B

    BufferedWriter

  • C

    Scanner

  • D

    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.

  • A

    true

  • B

    false

  • C

    null

  • D

    Compilation Error

Question 8

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

  • A

    getSize()

  • B

    getLength()

  • C

    length()

  • D

    size()

Question 9

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

  • A

    Throws an exception

  • B

    Returns false

  • C

    Returns null

  • D

    Returns the file name

Question 10

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

  • A

    File.mkdir()

  • B

    File.createDirectory()

  • C

    File.createDir()

  • D

    File.makeDirectory()

There are 12 questions to complete.

Take a part in the ongoing discussion