How to Edit and Save Text (txt) Files in Julia
write()
write(path, string)
The basic function write()
saves a .txt file whose contents are the input string.
julia> fm = "프로미스나인\n송하영\n박지원\n이채영\n이나경\n백지헌"
"프로미스나인\n송하영\n박지원\n이채영\n이나경\n백지헌"
julia> write("fm.txt", fm)
68
open ... do
Opens a file and manipulates the object directly. To achieve the same result as above, write as follows. The output produced by println()
is written to the file.
julia> fm = ["프로미스나인", "송하영", "박지원", "이채영", "이나경", "백지헌"]
6-element Vector{String}:
"프로미스나인"
"송하영"
"박지원"
"이채영"
"이나경"
"백지헌"
julia> open("fm.txt", "w") do f
for line ∈ fm
println(f, line)
end
end
See also
Environment
- OS: Windows 11
- Version: Julia 1.11.3