# File.new raise an exception?

**URL:** <https://www.ruby-forum.com/t/file-new-raise-an-exception/87326>\
**Category:** Ruby\
**Created:** [March 26, 2006, 5:51pm UTC](https://www.ruby-forum.com/t/file-new-raise-an-exception/87326 "2006-03-26T17:51:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jean-FranSSSSois\_Bo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bbe5ce/32.png) [@Jean-FranSSSSois\_Bo](https://www.ruby-forum.com/u/Jean-FranSSSSois_Bo)\
**Post date:** [March 26, 2006, 5:51pm UTC](https://www.ruby-forum.com/t/file-new-raise-an-exception/87326/1 "2006-03-26T17:51:15Z")

</div>

Hello,

I’m pretty new to ruby and I’ve written some code to parse apache  
logs, it works but now I want to store the result in a file. The  
problem is as follow (using irb)

irb(main):001:0\> foo = File.open(“test”)  
Errno::ENOENT: No such file or directory - test  
from (irb):1:in `initialize' from (irb):1:in`open’  
from (irb):1

I just do not understand the problem ( I can create a file with  
python in the same directory ), what’s wrong for me ?

thanks for a quick answer

Jean-François

---

<div class="post-metadata">

**Author:** ![Jean-FranSSSSois\_Bo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bbe5ce/32.png) [@Jean-FranSSSSois\_Bo](https://www.ruby-forum.com/u/Jean-FranSSSSois_Bo)\
**Post date:** [March 26, 2006, 6:39pm UTC](https://www.ruby-forum.com/t/file-new-raise-an-exception/87326/2 "2006-03-26T18:39:12Z")

</div>

Jean-FranÃ§ois Boisvieux [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) schrieb:

> irb(main):001:0\> foo = File.open(“test”)  
> Errno::ENOENT: No such file or directory - test  
> from (irb):1:in `initialize' from (irb):1:in `open’  
> from (irb):1
> 
> I just do not understand the problem ( I can create a file with  
> python in the same directory ), what’s wrong for me ?

Ruby is opening the file for reading per default. As there seems to be  
no file with the name test, you get the error. To open it for writing,  
you have to say

File.open(“test”, “w”)

Patrick

---

<div class="post-metadata">

**Author:** ![Jean-FranSSSSois\_Bo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bbe5ce/32.png) [@Jean-FranSSSSois\_Bo](https://www.ruby-forum.com/u/Jean-FranSSSSois_Bo)\
**Post date:** [March 26, 2006, 6:58pm UTC](https://www.ruby-forum.com/t/file-new-raise-an-exception/87326/3 "2006-03-26T18:58:19Z")

</div>

Thanks Patrick for this precise and clear answer

Jean-Francois

Le 26 mars 06 à 18:38, Patrick Hof a écrit :
