Ruby 如何解决 File.open 的错误

KUMU · July 25, 2025 · Last by averytarwater replied at August 01, 2025 · 277 hits

在某些 windows 系统中,由于 null.sys 文件的损坏,会导致系统中的 nul 不能用,这时你用 ruby 的运行 File.open("1.txt","wb") 就会报错: in `initialize': Too many open files @ rb_sysopen - 1.txt (Errno::EMFILE) 现在一般是从好的电脑拷贝个 null.sys 文件来替换掉他,让 nul 有效才行,有没有什么办法可以就算 nul 无效也能让 File.open("1.txt","wb") 可以正常运行

https://www.runoob.com/ruby/ruby-file-methods.html
看到 file 类中有不少方法,看看哪个适用。不行的话就用异常捕捉 rescue

You need to Sign in before reply, if you don't have an account, please Sign up first.