I have a really large file that "should" consist of JSON strings. However, when I use the following code, I get a "stream did not contain valid UTF8".
let file = File::open("foo.txt")?;
let reader = BufReader::new(file);
for line in reader.lines() {
println!("{}", line?);
}
Ok(())
Now the answer to this is to use Vec rather than String. But all the code I've seen has file.read_to_end(buf)
as the answer which won't work for the filesizes I have to work with.
What I'm looking for is to read the file line by line, use lossy utf8 conversion and then do some calculations and push the output to another file.