[][src]Function tokio_fs::read

pub fn read<P>(path: P) -> ReadFile<P> where
    P: AsRef<Path> + Send + 'static, 

Creates a future which will open a file for reading and read the entire contents into a buffer and return said buffer.

This is the async equivalent of std::fs::read.

Examples

use tokio::prelude::Future;
fn main() {
    let task = tokio::fs::read("foo.txt").map(|data| {
        // do something with the contents of the file ...
        println!("foo.txt contains {} bytes", data.len());
    }).map_err(|e| {
        // handle errors
        eprintln!("IO error: {:?}", e);
    });
    tokio::run(task);
}