أمثلة على التعامل مع الملفات في روبي Ruby
- 2020-10-06
توصيف
كود الكتابة في ملف :
aFile = File.new("input.txt", "r+")
if aFile
aFile.syswrite("ABCDEF")
else
puts "Unable to open file!"
end
كود القراءة من ملف :
aFile = File.new("input.txt", "r")
if aFile
content = aFile.sysread(20)
puts content
else
puts "Unable to open file!"
end
كود اعادة تسمية ملف :
# Rename a file from test1.txt to test2.txt
File.rename( "test1.txt", "test2.txt" )
كود حذف ملف :
# Delete file test2.txt
File.delete("test2.txt")