Skip to main content

File Input Output In Ruby MCQs with Explanations

Practice high-yield Programming & Software Development MCQs on File Input Output In Ruby with worked academic solutions for FPSC, PPSC, NTS, NITB, PTS.

Questions
33
Difficulty Level
Exam-Level
Target Exams
FPSC, PPSC, NTS...
Estimated Time
40 mins
Exam-Level FPSC PPSC NTS NITB PTS
Verified for Commission Syllabus • Oct 14, 2026
33

Verified Practice Questions

Interactive test mode with detailed academic worked solutions

Live Progress | 0/33 answered
✓ 0 correct ✗ 0 wrong 0% score
Question 1 of 33
★ FPSC ★ PPSC

What does File.open() return in Ruby when the file is successfully opened?

Question 2 of 33
★ FPSC ★ PPSC

How do you open a file in Ruby in write mode, creating it if it does not exist?

Question 3 of 33
★ FPSC ★ PPSC

Which method in Ruby is used to read a line from a file?

Question 4 of 33
★ FPSC ★ PPSC

What is the purpose of the File.readlines() method in Ruby?

Question 5 of 33
★ FPSC ★ PPSC

How do you close a file in Ruby after performing file operations?

Question 6 of 33
★ FPSC ★ PPSC

Which method in Ruby is used to write data to a file?

Question 7 of 33
★ FPSC ★ PPSC

What does the 'a+' file mode in Ruby signify?

Question 8 of 33
★ FPSC ★ PPSC

Which method in Ruby is used to check if the end of a file has been reached?

Question 9 of 33
★ FPSC ★ PPSC

What does the File.exist? method in Ruby return if the specified file exists?

Question 10 of 33
★ FPSC ★ PPSC

What does the 'r+' file mode in Ruby signify?

Question 11 of 33
★ FPSC ★ PPSC

What is the purpose of the File.exist? method in Ruby?

Question 12 of 33
★ FPSC ★ PPSC

Which method in Ruby is used to set the position of the file pointer?

Question 13 of 33
★ FPSC ★ PPSC

What does the File.rename() method in Ruby do?

Question 14 of 33
★ FPSC ★ PPSC

How do you read the entire contents of a file into a string in Ruby?

Question 15 of 33
★ FPSC ★ PPSC

Which method in Ruby is used to delete a file?

Question 16 of 33
★ FPSC ★ PPSC

What is the purpose of the File.size method in Ruby?

Question 17 of 33
★ FPSC ★ PPSC

What is the result of using File.open() with the block syntax in Ruby?

Question 18 of 33
★ FPSC ★ PPSC

What does the 'w' file mode in Ruby signify?

Question 19 of 33
★ FPSC ★ PPSC

How do you check if a file in Ruby is readable?

Question 20 of 33
★ FPSC ★ PPSC

What method is used to check if a file is writable in Ruby?

Question 21 of 33
★ FPSC ★ PPSC

How do you check the size of a file in Ruby?

Question 22 of 33
★ FPSC ★ PPSC

Which method is used to delete a file in Ruby?

Question 23 of 33
★ FPSC ★ PPSC

What does the binmode method do in Ruby file I/O?

Question 24 of 33
★ FPSC ★ PPSC

How can you check if a file is readable in Ruby?

Question 25 of 33
★ FPSC ★ PPSC

What does the truncate method do in Ruby file I/O?

Question 26 of 33
★ FPSC ★ PPSC

Which method is used to check if a file is executable in Ruby?

Question 27 of 33
★ FPSC ★ PPSC

How can you get the absolute path of a file in Ruby?

Question 28 of 33
★ FPSC ★ PPSC

What does the fcntl method do in Ruby file I/O?

Question 29 of 33
★ FPSC ★ PPSC

How do you create a new directory in Ruby?

Question 30 of 33
★ FPSC ★ PPSC

What is the purpose of the chown method in Ruby file I/O?

Question 31 of 33
★ FPSC ★ PPSC

Which method is used to check if a file is hidden in Ruby?

Question 32 of 33
★ FPSC ★ PPSC

What does the ctime method return in Ruby file I/O?

Question 33 of 33
★ FPSC ★ PPSC

Which method is used to retrieve file attributes in Ruby?

✓ Link copied to clipboard
Continue Your Practice

Advance Html — Part 1

Master the next curriculum module with 40 exam-standard MCQs.

Next Practice Set →

💡 Examiner's Advisory for Programming & Software Development

In competitive commission exams (FPSC, PPSC, KPPSC, SPSC, CSS, PMS), questions are frequently phrased with distractor options designed to catch rote learners. Whenever you answer an MCQ, read the Detailed Academic Explanation and Conceptual Anchor to understand why the remaining options are incorrect.

More Modules in Programming & Software Development

View All →
📚

Study Guides

Topic summaries and syllabus breakdown

Explore Guides →
🎯

Complete Library

Search through 78,000+ verified MCQs

Browse Library →
📱

Mobile App

Offline mock tests and instant bookmarks

Get Mobile App →