如何获取被声明为File
变量的文件的大小/长度?
可以通过使用文件名并调用fs::metadata
来获取大小:
let x = fs::metadata(file_path)?.len();
但我有一个已经创建并编辑过的文件:
let mut my_file = File::create(file_path).unwrap();
my_file.write_all(buffer) // buffer is a data which comes from network and put into Vec<u8>
// From here, does it possible to get my_file length?
// Looking something like my_file.len();
是否有任何函数可以给出File
的长度?