How to read a file line by line in Julia?

Reading a file into memory all at once as an array of lines is just a call to the readlines function: julia> words = readlines(“/usr/share/dict/words”) 235886-element Array{String,1}: “A” “a” “aa” ⋮ “zythum” “Zyzomys” “Zyzzogeton” By default this discards the newlines but if you want to keep them, you can pass the keyword argument keep=true: julia> … Read more

What is the best variant for appending a new line in a text file?

Using OpenOptions::append is the clearest way to append to a file: use std::fs::OpenOptions; use std::io::prelude::*; fn main() { let mut file = OpenOptions::new() .write(true) .append(true) .open(“my-file”) .unwrap(); if let Err(e) = writeln!(file, “A new line!”) { eprintln!(“Couldn’t write to file: {}”, e); } } As of Rust 1.8.0 (commit) and RFC 1252, append(true) implies write(true). … Read more

How to read a binary file in Go

For manipulating files, the os package is your friend: f, err := os.Open(“myfile”) if err != nil { panic(err) } defer f.Close() For more control over how the file is open, see os.OpenFile() instead (doc). For reading files, there are many ways. The os.File type returned by os.Open (the f in the above example) implements … Read more

Groovy write to file (newline)

As @Steven points out, a better way would be: public void writeToFile(def directory, def fileName, def extension, def infoList) { new File(“$directory/$fileName$extension”).withWriter { out -> infoList.each { out.println it } } } As this handles the line separator for you, and handles closing the writer as well (and doesn’t open and close the file each … Read more

tech