Task

(Over)write a file so that it contains a string.



The reverse of Read entire file—for when you want to update or create a file which you would read in its entirety all at once.




import "io" for File
 
// create a text file
File.create("hello.txt") { |file|
    file.writeBytes("hello")
}
 
// check it worked
System.print(File.read("hello.txt"))
 
// overwrite it by 'creating' the file again
File.create("hello.txt") {|file|
    file.writeBytes("goodbye")
}
 
// check it worked
System.print(File.read("hello.txt"))