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.txtand 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 use regular expressions in JuliaLang?
- How to use tuples in JuliaLang?
- How to round numbers in JuliaLang?
- How to use try catch in JuliaLang?
- How to use channels in JuliaLang?
- How to calculate the mean in JuliaLang?
- How to add a legend to a plot in JuliaLang?
- How to use interpolation in JuliaLang?
- How to install JuliaLang on Linux?
See more codes...