2015-06-19 77 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

不用擔心,你能接受答案嗎? –