read a file:
input_file =File.new (filename, ‘r’)
write a file:
output_file= File.new( filename, ‘w’)
‘w+’:
read and write. When creating the file, the old file is overwritten
'a':
append
read:
return the content of the file in the string
readlines:
output_file.readlines()
return an array with each line of the file
puts:
output_file.puts(“hello”)
write “hello” to output_file
close:
output_file.close()
close the file
show the files and directories under directory:
ex:
Dir.open("Desktop").entries
---> [ "." , "..", "test.c", "book"]
directory?
ex:
File.directory?("test")
extname:
ex:
File.extname("test.exe")
--> ".exe"
沒有留言:
張貼留言