当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Julia readlines用法及代码示例


用法:

readlines(io::IO=stdin; keep::Bool=false)
readlines(filename::AbstractString; keep::Bool=false)

将 I/O 流或文件的所有行作为字符串向量读取。行为等同于保存使用相同参数重复读取 readline 的结果并将结果行保存为字符串向量。

例子

julia> open("my_file.txt", "w") do io
           write(io, "JuliaLang is a GitHub organization.\nIt has many members.\n");
       end
57

julia> readlines("my_file.txt")
2-element Vector{String}:
 "JuliaLang is a GitHub organization."
 "It has many members."

julia> readlines("my_file.txt", keep=true)
2-element Vector{String}:
 "JuliaLang is a GitHub organization.\n"
 "It has many members.\n"

julia> rm("my_file.txt")

相关用法


注:本文由纯净天空筛选整理自julialang.org 大神的英文原创作品 Base.readlines — Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。