Topic: File.new issues

I am trying to save a file to my file system, and I am trying to use something very simple just to test it out:

string = 'My String'
file = File.new('test.txt')
file.write(string)
file.close

only it doesn't work.  Instead, I am told that no such file or directory exists, which of course, I knew that already.  That's why I made the call to File.new.  Any suggestions?

Last edited by dsullivan (2011-02-11 15:35:32)

Re: File.new issues

File.open("test.txt","w") {|f| f.write('MyString') }

Open the file, create it if it doesn't exist and open for writing "w"

The opened file descriptor is passed to the following block, where you write to it.  The file is closed when the block exits.

Joe got a job, on the day shift, at the Utility Muffin Research Kitchen, arrogantly twisting the sterile canvas snout of a fully charged icing anointment utensil.

Re: File.new issues

Worked like a charm.  Thanks!