use std::io::IoSlice;
use std::io::prelude::*;
use std::fs;
use std::fs::OpenOptions;
fn main() -> std::io::Result<()> {
let mut data1 = [1; 8];
let mut data2 = [15; 8];
let io_slice1 = IoSlice::new(&mut data1);
let io_slice2 = IoSlice::new(&mut data2);
let mut f = OpenOptions::new().write(true).read(true).create(true).open("foo.txt").unwrap();
f.write_vectored(&[io_slice1, io_slice2])?;
f.flush()?;
let mut buffer = [0; 16];
let n = f.read(&mut buffer[..])?;
println!("The lens: {:?}", n);
println!("The bytes: {:?}", &buffer[..n]);
println!("{:?}", fs::read_to_string("foo.txt")?.as_bytes());
Ok(())
}
1
共 2 条评论, 1 页
评论区
写评论你把
foo.txt
文件加长一点 对比一下自己就能明白了你需要seek一下,让文件的cursor回到文件开头。
参考链接: