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 append to an array in JuliaLang?
- How to measure execution time in JuliaLang?
- How to use tuples in JuliaLang?
- How to create plots in JuliaLang?
- How to use JuliaLang to perform a Fast Fourier Transform?
- How to install JuliaLang?
- How to use addprocs in JuliaLang?
- How to convert a string to an integer in JuliaLang?
- How to create a package in JuliaLang?
See more codes...