julialangHow to read lines from file in JuliaLang?
Reading lines from a file in JuliaLang is a simple process. The following example code block reads a file line by line and prints each line to the console:
f = open("myfile.txt")
for line in eachline(f)
println(line)
end
close(f)
The output of the code above would be the contents of the file myfile.txt
printed to the console.
The code consists of the following parts:
f = open("myfile.txt")
- This opens the filemyfile.txt
and assigns it to the variablef
.for line in eachline(f)
- This starts a loop that iterates over each line in the filef
.println(line)
- This prints the current line to the console.end
- This ends the loop.close(f)
- This closes the filef
.
For more information, see the JuliaLang documentation.
More of Julialang
- How to test code in JuliaLang?
- How to sort in JuliaLang?
- How to round numbers in JuliaLang?
- How to use assert in JuliaLang?
- How to measure execution time in JuliaLang?
- How to create plots in JuliaLang?
- How to use the println function in JuliaLang?
- How to work with rational numbers in JuliaLang?
- How to use regular expressions in JuliaLang?
- How to install JuliaLang?
See more codes...