Question : read file contents in rust
Answered by : bijay-poudel
use std::fs;
fn main() { let data = fs::read_to_string("file_name.txt").expect("Unable to read file"); println!("{}", data);
}
Source : | Last Update : Mon, 20 Sep 21
Question : how to open a file rust
Answered by : coding-wizard
use std::fs::File;
fn main() -> std::io::Result<()> { let mut f = File::open("foo.txt")?; Ok(())
}
Source : https://doc.rust-lang.org/stable/std/fs/struct.File.html | Last Update : Thu, 03 Mar 22
Question : read file Rust
Answered by : ahmad-khaefi
use std::fs;
fn main() { let content = match fs::read_to_string("Cargo.toml") { Result::Ok(value) => value, Result::Err(error) => panic!("{}", error) }; println!("{}", content)
}
Source : | Last Update : Thu, 09 Jun 22
Question : c# read file stream
Answered by : amused-angelfish-g1hco48qsu8r
//this will get a string with all the text from the file
var fileText = File.ReadAllText(@"path\to\my\file.txt");
//this will get all of the lines of the file as an string[]
var fileLines = File.ReadAllLines(@"path\to\my\file.txt");
Source : | Last Update : Mon, 24 Feb 20