Site icon DataFlair

Quiz on Java File Class

quiz on java file class

Get Job-ready: Java Course with 45+ Real-time Projects! - Learn Java

In the world of Java programming, working with files is like having a toolbox for your data. The `File` class acts as this very toolbox, offering a powerful set of tools to interact with the file system on your computer. This means you can create new files, modify existing ones, and even access information about them.

This quiz dives deep into your understanding of the `File` class, testing your knowledge of the essential methods and functionalities it provides. Whether you’re a seasoned Java developer who’s been building complex applications for years, or a curious beginner just starting your programming journey, this quiz serves as a valuable tool to assess your grasp of file operations in Java.

By taking the quiz, you’ll not only challenge yourself but also gain valuable insights into how effectively you can use the `File` class to manage your data within the file system. So, are you ready to test your file handling skills in Java? Let’s test your knowledge.

Time limit: 0

Quiz Summary

0 of 15 Questions completed

Questions:

Information

You have already completed the quiz before. Hence you can not start it again.

Quiz is loading…

You must sign in or sign up to start the quiz.

You must first complete the following:

Results

Quiz complete. Results are being recorded.

Results

0 of 15 Questions answered correctly

Your time:

Time has elapsed

You have reached 0 of 0 point(s), (0)

Earned Point(s): 0 of 0, (0)
0 Essay(s) Pending (Possible Point(s): 0)

Categories

  1. Not categorized 0%
  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  1. Current
  2. Review / Skip
  3. Answered
  4. Correct
  5. Incorrect
  1. Question 1 of 15
    1. Question

    Which of the following is used to get the input characters from a file ?

    Correct
    Incorrect
  2. Question 2 of 15
    2. Question

    class  FileClass {

    public static void main ( String args [ ] )

    {

    String message = “ DataFlair “;

    Path filepath = Path.of(“C:\Program Files\Android\Android Studio\file.txt”);

    File.writeString( filepath , message );

    }

    }

    Correct
    Incorrect
  3. Question 3 of 15
    3. Question

     class FileWriterClass {

    String text = “This is a method to write in file “;

    public static void main ( String args [ ] )

    {

    FileWriter writer = new Filewriter(“C:\Program Files\JAVA\JavaPrograms\FileWriterClass”);

    writer.write(text);

    System.out.println(text);

    writer.close();

    }

    }

    Correct
    Incorrect
  4. Question 4 of 15
    4. Question

    Which of the following cannot be performed by file class in Java ?

    Correct
    Incorrect
  5. Question 5 of 15
    5. Question

    Which of the following is not the correct syntax for writing content into a file ?

    Correct
    Incorrect
  6. Question 6 of 15
    6. Question

    class FileClass {

    public static void main ( String args[ ] )

    {

    File file = new File(“C:\Program Files\JAVA\JavaPrograms\FileClass”);

    FileInputStream input = new FileInputStream(file);

    InputStreamReader reader = new InputStreamReader(input);

    BufferReader buffer = new BufferReader(reader);

    String text;

    While(text=buffer.readline()!=null){

    System.out.println(“file is opened”);

    }

    buffer.close();

    }

    }

    Correct
    Incorrect
  7. Question 7 of 15
    7. Question

     class FilePermissions {

    public static void main ( String args [ ] )

    {

    File file = new File(“C:\Program Files\JAVA\JavaPrograms\FilePermissions”);

    file.setReadable(true,false);

    file.setWritable(true,false);

    file.setExecutable(true,true);

    }

    }

    Correct
    Incorrect
  8. Question 8 of 15
    8. Question

    class FileDelete {

    public static void main ( String args [ ] )

    {

    File file = new File(“C:\Program Files\JAVA\JavaPrograms\FileDelete”);

    InputReader input = new InputReader(file);

    InputStream str = new InputStream(input);

    BufferReader reader = new BufferReader(str);

    String Text = file.readline();

    file.delete();

    System.out.println(Text);

    }

    }

    Correct
    Incorrect
  9. Question 9 of 15
    9. Question

    Which of the following methods is used to get the number of unallocated bytes in partition ?

    Correct
    Incorrect
  10. Question 10 of 15
    10. Question

    class Files {

    public static void main ( String args [ ] )

    {

    File file = new File(“C:\Program Files\JAVA\JavaPrograms\Files”);

    file.delete();

    String content = file.readline();

    }

    }

    Correct
    Incorrect
  11. Question 11 of 15
    11. Question

    class Length {

    public static void main ( String args [ ] )

    {

    File file = new File(“C\ProgramFiles\Java\Length”);

    String content = “New File”;

    file.write(content);

    System.out.println(file.length());

    }

    }

    Correct
    Incorrect
  12. Question 12 of 15
    12. Question

    What is the input to perform any operation of the file ?

    Correct
    Incorrect
  13. Question 13 of 15
    13. Question

    class FileOperation {

    public static void main ( String args [ ] )

    {

    File file = new File(“C\ProgramFiles\Java\FileOperations”);

    file.getname();

    }

    }

    Correct
    Incorrect
  14. Question 14 of 15
    14. Question

    What is the function of the public boolean setReadOnly() method ?

    Correct
    Incorrect
  15. Question 15 of 15
    15. Question

    class FileClass {

    public static void main ( String args [ ] )

    {

    File file = new File(“C\ProgramFiles\Java\FileClass”);

    if(File.mkdir())

    {

    System.out.println(“File is present in new directory”);

    }

    else

    {

    System.out.println(“File is present in the same directory”);

    }

    }

    }

    Correct
    Incorrect

Summary:

Have you put your Java file handling skills to the test? This quiz covered various aspects of the `File` class, including methods for checking file existence, retrieving file paths, and creating new files. By attempting this quiz, you’ve gained valuable insights into your understanding of file operations in Java.

If you aced the quiz, congratulations! You’ve demonstrated a solid grasp of file handling concepts in Java. If you encounter some challenges, don’t worry! This is a great opportunity to revisit the `File` class documentation and explore online tutorials and resources to solidify your understanding. Remember, consistent practice is key to mastering file operations in Java.

Exit mobile version