rust - How to read a GBK-encoded file into a String? -


use std::env; use std::fs::file; use std::io::prelude::*;  fn main() {     let args: vec<string> = env::args().collect();     let filename = &args[1];     let mut f = file::open(filename).expect("file not found");     let mut contents = string::new();     f.read_to_string(&mut contents).expect("something went wrong reading file");     println!("file content:\n{}", contents); } 

when attempt read gbk encoded file, following error:

thread 'main' panicked @ 'something went wrong reading file: error { repr: custom(custom { kind: invaliddata, error: stringerror("stream did not contain valid utf-8") }) }', /checkout/src/libcore/result.rs:860 

it says stream must contain valid utf-8. how can read gbk file?

you want encoding crate.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -