Created
November 19, 2021 06:33
-
-
Save rozer007/df9fe1ff43c2bceac1b3c5a6a2cbea95 to your computer and use it in GitHub Desktop.
File IO
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Q1) What is difference between a and a+ mode? | |
ans: a - Append to a file.The file is created if it does not exist. | |
a+ - Open a file for reading and appending. The file is created if it does not exist. | |
Q2) Is it mandatory to close the file after opening. | |
ans: Yes ,if we didn't close then it will leak file descriptors. | |
Q3) When we use File.open() ,what type of object is created? | |
ans: File object ,it can be check using .class function. | |
Q4) Does a mode create a new file if the file doesn't exist ? | |
ans Yes, it will create then the content will be append. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Q1) Which of the following is not a function of File IO? | |
a) writeLine | |
b) gets | |
c) puts | |
d) read | |
ans: a)write | |
Q2) Which mode is used to write at the end of the file ? | |
a) a | |
b) w | |
c) both a and b | |
d) None of the above | |
ans: a) | |
Q3) Which function is use to insert content in file ? | |
a) puts | |
b) write | |
c) Only a | |
d) both a and b | |
Q4) What will be the output of this program : | |
f1=File.new("authors.txt","w") | |
f1.puts "PK" | |
f1.puts "RK" | |
f1.puts "KK" | |
f1.puts "LK" | |
f1.close | |
f1=File.open("authors.txt","w") | |
f1.puts "ll" | |
f1.close | |
puts File.read("authors.txt") | |
a) ll | |
b) error | |
c) PK | |
RK | |
KK | |
LK | |
d) PK | |
RK | |
KK | |
LK | |
ll | |
ans: a) ll |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment