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.
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
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
- Not categorized 0%
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- Current
- Review / Skip
- Answered
- Correct
- Incorrect
-
Question 1 of 15
1. Question
Which of the following is used to get the input characters from a file ?
CorrectIncorrect -
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 );
}
}
CorrectIncorrect -
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();
}
}
CorrectIncorrect -
Question 4 of 15
4. Question
Which of the following cannot be performed by file class in Java ?
CorrectIncorrect -
Question 5 of 15
5. Question
Which of the following is not the correct syntax for writing content into a file ?
CorrectIncorrect -
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();
}
}
CorrectIncorrect -
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);
}
}
CorrectIncorrect -
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);
}
}
CorrectIncorrect -
Question 9 of 15
9. Question
Which of the following methods is used to get the number of unallocated bytes in partition ?
CorrectIncorrect -
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();
}
}
CorrectIncorrect -
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());
}
}
CorrectIncorrect -
Question 12 of 15
12. Question
What is the input to perform any operation of the file ?
CorrectIncorrect -
Question 13 of 15
13. Question
class FileOperation {
public static void main ( String args [ ] )
{
File file = new File(“C\ProgramFiles\Java\FileOperations”);
file.getname();
}
}
CorrectIncorrect -
Question 14 of 15
14. Question
What is the function of the public boolean setReadOnly() method ?
CorrectIncorrect -
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”);
}
}
}
CorrectIncorrect
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.
