Skip to content

Commit 318f0ea

Browse files
authored
docs: first describe simple read and write without streaming (#49834)
1 parent c63feee commit 318f0ea

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

doc/src/manual/networking-and-streams.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,28 @@ of common properties.
120120

121121
## Working with Files
122122

123-
Like many other environments, Julia has an [`open`](@ref) function, which takes a filename and
123+
You can write content to a file with the `write(filename::String, content)` method:
124+
125+
```julia-repl
126+
julia> write("hello.txt", "Hello, World!")
127+
13
128+
```
129+
130+
_(`13` is the number of bytes written.)_
131+
132+
You can read the contents of a file with the `read(filename::String)` method, or `read(filename::String, String)`
133+
to the contents as a string:
134+
135+
```julia-repl
136+
julia> read("hello.txt", String)
137+
"Hello, World!"
138+
```
139+
140+
141+
### Advanced: streaming files
142+
143+
The `read` and `write` methods above allow you to read and write file contents. Like many other
144+
environments, Julia also has an [`open`](@ref) function, which takes a filename and
124145
returns an [`IOStream`](@ref) object that you can use to read and write things from the file. For example,
125146
if we have a file, `hello.txt`, whose contents are `Hello, World!`:
126147

0 commit comments

Comments
 (0)