http://www.cnblogs.com/cnblogsfans/archive/2009/09/19/1569918.html
http://www.cnblogs.com/cnblogsfans/archive/2009/09/17/1568804.html
二、读取文件
1file=File.open(File.join("C:","Test.txt"),"r")
2file.each { |line| print "#{file.lineno}.", line }
3file.close
一、新建文件
1f=File.new(File.join("C:","Test.txt"), "w+")
2f.puts("I am Jack")
3f.puts("Hello World")
文件模式
"r" :Read-only. Starts at beginning of file (default mode).
"r+" :Read-write. Starts at beginning of file.
"w" :Write-only. Truncates existing file to zero length or creates a new file for writing.
"w+" :Read-write. Truncates existing file to zero length or creates a new file for reading and writing.
"a" :Write-only. Starts at end of file if file exists; otherwise, creates a new file for writing.
"a+" :Read-write. Starts at end of file if file exists; otherwise, creates a new file for reading and writing.
"b" :(DOS/Windows only.) Binary file mode. May appear with any of the key letters listed above
浙公网安备 33010602011771号