Rust 如何从Vec写入文件<;u8>;?
我有一个base64图像,从中获得Rust 如何从Vec写入文件<;u8>;?,rust,io,base64,vec,Rust,Io,Base64,Vec,我有一个base64图像,从中获得Vec,并将它们写入一个文件。 这是我的密码: let file\u contents\u base64:Vec=image\u base64::from\u base64( String::from(&file\u contents\u String\u vec[0]) ); 我想将file\u contents\u base64变量写入文件。使用。考虑到您只想将一个Vec写入一个文件,那么您可以只使用例如: 使用std::fs; 使用std::path::
Vec
,并将它们写入一个文件。
这是我的密码:
let file\u contents\u base64:Vec=image\u base64::from\u base64(
String::from(&file\u contents\u String\u vec[0])
);
我想将
file\u contents\u base64
变量写入文件。使用。考虑到您只想将一个Vec
写入一个文件,那么您可以只使用例如:
使用std::fs;
使用std::path::path;
让文件_contents_base64:Vec=。。。;
让路径:&path=。。。;
fs::write(路径、文件内容);
除了fs::write
,还有一个通用的解决方案,用于实现该特性的所有方面,使用:
使用std::io::Write;//将特性纳入范围
使用std::fs;
// ... 以后的代码
让file=OpenOptions::new()
.写(真)
//用哪一种?或展开,因为它返回一个结果
.open(“/path/to/file”)?;
file.write_all(&file_contents_base64);
请在回答之前查找重复项并投票结束问题。请在回答之前查找重复项并投票结束问题。