Read entire file: Difference between revisions

m
Line 997:
 
=={{header|Julia}}==
The built-in function <code>read</code>, when used with a second argument of String, reads the whole file named by its first argument into a string (assuming UTF8 encoding).
{{incorrect|Julia|readstring is deprecated}}
<lang Julia>readstringread("/devel/myfile.txt", String) # read file into a string</lang>
The built-in function <code>readstring</code> reads a whole file into a string (assuming UTF8 encoding), or you can also use read to read the content into an array of bytes:
Alternatively, for files that are too large to read into memory without swapping, there are a variety of ways to memory-map the file, herefor example as an array of bytes:
<lang Julia>readstring("/devel/myfile.txt") # read file into a string
read("/devel/myfile.txt", filesize("/devel/myfile.txt")) # read file into an array of bytes</lang>
Alternatively, there are a variety of ways to memory-map the file, here as an array of bytes:
<lang Julia>A = Mmap.mmap(open("/devel/myfile.txt"), Array{UInt8,1})</lang>
 
4,105

edits