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 work with rational numbers in JuliaLang?
- How to test code in JuliaLang?
- How to use try catch in JuliaLang?
- How to round numbers in JuliaLang?
- How to create dataframes in JuliaLang?
- How to convert a string to an integer in JuliaLang?
- How to create plots in JuliaLang?
- How to install JuliaLang?
- How to use channels in JuliaLang?
- How to use addprocs in JuliaLang?
See more codes...