Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
15
Task/Read-entire-file/Rust/read-entire-file.rust
Normal file
15
Task/Read-entire-file/Rust/read-entire-file.rust
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
use std::fs::File;
|
||||
use std::io::Read;
|
||||
|
||||
fn main() {
|
||||
let mut file = File::open("somefile.txt").unwrap();
|
||||
|
||||
let mut contents: Vec<u8> = Vec::new();
|
||||
// Returns amount of bytes read and append the result to the buffer
|
||||
let result = file.read_to_end(&mut contents).unwrap();
|
||||
println!("Read {} bytes", result);
|
||||
|
||||
// To print the contents of the file
|
||||
let filestr = String::from_utf8(contents).unwrap();
|
||||
println!("{}", filestr);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue