Ruby Rhomobile:读取txt文件并显示内容
我想在我的移动应用程序中打开、读取和显示txt文件。 首先,我想显示文件的完整内容。但这是我的问题Ruby Rhomobile:读取txt文件并显示内容,ruby,rhomobile,rhodes,Ruby,Rhomobile,Rhodes,我想在我的移动应用程序中打开、读取和显示txt文件。 首先,我想显示文件的完整内容。但这是我的问题 def text fileName = File.join(Rho::RhoApplication::get_base_app_path(), '/app/test.txt') f = File.open(fileName, 'r') while line = f.gets puts line end f.close redirect :action =
def text
fileName = File.join(Rho::RhoApplication::get_base_app_path(), '/app/test.txt')
f = File.open(fileName, 'r')
while line = f.gets
puts line
end
f.close
redirect :action => :index
end
代码读取txt文件,但是如何调用该方法并在页面上显示结果。
我不知道变量是什么
请帮帮我:)非常感谢 如果您只想读取整个文件,可以使用以下方法:
@file_content = File.read(fileName);
您可以将文件内容分配给实例变量(前缀为@),并在视图中显示它(*.html.erb
或*.erb
):
File content: <%= @file_content %>
def text
@file_content = File.read(fileName);
render action: 'text'
end