Content-Length: 9407 | pFad | https://doc.rust-lang.org/std/pin/../default/../rc/../../../../std/io/../fs/fn.read.html

read in std::fs - Rust

read

Function read 

1.26.0 · Source
pub fn read<P: AsRef<Path>>(path: P) -> Result<Vec<u8>>
Expand description

Reads the entire contents of a file into a bytes vector.

This is a convenience function for using File::open and read_to_end with fewer imports and without an intermediate variable.

§Errors

This function will return an error if path does not already exist. Other errors may also be returned according to OpenOptions::open.

While reading from the file, this function handles io::ErrorKind::Interrupted with automatic retries. See io::Read documentation for details.

§Examples

use std::fs;

fn main() -> Result<(), Box<dyn std::error::Error + 'static>> {
    let data: Vec<u8> = fs::read("image.jpg")?;
    assert_eq!(data[0..3], [0xFF, 0xD8, 0xFF]);
    Ok(())
}








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://doc.rust-lang.org/std/pin/../default/../rc/../../../../std/io/../fs/fn.read.html

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy