How to create a file

Z

Zhao Yi

I use this code to write to a file: File.new(@FILE_NAME,"w"). If the
file name doesn't exist, I will get "No such file" error. How can I
create the file if it doesn't exist?

thanks.
 
R

Robert Klemme

D

Dave Bass

It could be that the operating system is unable to create a file with
that file name. For instance on Windows:

C:\>irb
irb(main):001:0> @FILE_NAME = "."
=> "."
irb(main):002:0> File.new(@FILE_NAME, "w")
Errno::EACCES: Permission denied - .
from (irb):2:in `initialize'
from (irb):2:in `new'
from (irb):2

This could be a particular problem when using international character
sets.

Dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,271
Latest member
BuyAtenaLabsCBD

Latest Threads

Top