julia 文件读取与文件写入示例代码

代码语言:julia

所属分类:其他

代码描述:julia 文件读取与文件写入示例代码

代码标签: 文件 写入 示例

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

outfile = "/data/wwwroot/default/Data/simple.dat"
# writing to files is very similar:
f = open(outfile, "w")
# both print and println can be used as usual but with f as their first arugment
println(f, "some content")
print(f, "more content")
print(f, " more on the same line")
close(f)

# we can then check the content of the file written
# "do" above just creates an anonymous function and passes it to open
# we can use the same logic to pass readall and thereby succinctly
# open, read and close a file in one line
outfile_content = open(f->read(f, String), outfile, "r")
println(repr(outfile_content))
#> "some content\nmore content more on the same line".........完整代码请登录后点击上方下载按钮下载查看

网友评论0