在Ruby中,可以使用以下方法打开并读取文件:
使用File.open方法打开文件并读取内容:File.open("example.txt", "r") do |file| puts file.readend使用File.read方法读取文件内容:content = File.read("example.txt")puts content使用IO.foreach方法逐行读取文件内容:IO.foreach("example.txt") do |line| puts lineend确保替换代码示例中的"example.txt"为你要打开的文件路径。


