簡體   English   中英

如何在ruby中的一行中打開和讀取文件

[英]How to open and read a file in one line in ruby

如何將其寫成一行?

in_file = open(from_file)
indata = in_file.read
File.read("/path/to/file")

它將讀取整個文件內容並將其作為結果返回。

open("README.md").read

對於非常小的文件,這是可以接受的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM