2015-06-19 37 views
0

同时插入内容到一个文件:文件显示错误

file1=File.new("output.txt","w+") 
    puts "enter the string" 
    in1=gets.chomp 
    if file1 
      file1.syswrite() 
    else 
     puts cant write 
    end 
    file1.close 
+0

什么错误?为什么lowlevel'syswrite'? – mudasobwa

+0

过去的错误,请 –

+0

我需要写的内容,目前在in1文件... –

回答

0

试试这个,它使用的File classwrite方法。记住,当你写一个看跌语句,随后的字符串需要加引号。

file1=File.new("output.txt","w+") 
puts "enter the string" 
in1=gets.chomp 
if file1 
    file1.write(in1) 
else 
    puts "can't write" 
end 
file1.close 
+0

谢谢.. bajwa –

+0

不用担心,你能接受答案吗? –