How to create a file in Ruby

后端 未结 9 1316
再見小時候
再見小時候 2020-11-28 18:04

I\'m trying to create a new file and things don\'t seem to be working as I expect them too. Here\'s what I\'ve tried:

File.new \"out.txt\"
File.open \"out.tx         


        
9条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-28 18:47

    You can also use constants instead of strings to specify the mode you want. The benefit is if you make a typo in a constant name, your program will raise an runtime exception.

    The constants are File::RDONLY or File::WRONLY or File::CREAT. You can also combine them if you like.

    Full description of file open modes on ruby-doc.org

提交回复
热议问题