Struct std::fs::File
A file.
Example
use std::fs::{File, Path};
use std::string::StringBuf;
let file = File::open(Path::new("/etc/passwd")).unwrap();
defer file.close();
let buf = StringBuf::new();
defer buf.free();
file.read_to_end(&buf).unwrap();
println!("{}", buf[..]);
Run this example
Fields
-
fd: FileDescriptor
Methods
impl File { ... }
-
Opens file in read-only mode.
-
Creates a new file for writing (truncating it if it already exists).
-
fn open_with(path: Path, opts: &OpenOptions) -> Result<File>
Opens file with custom options.
-
Returns the file attributes (
stat
) for the file -
fn from_fd(fd: FileDescriptor) -> File
Create a file object from an existing file descriptor.
-
fn as_fd(self: &File) -> FileDescriptor
Get the file descriptor for the file.
-
Read the entire file into a StringBuf.
-
Jump to a specified position in the stream.
Returns the new position in the stream from the beginning.
-
Flush the stream
This may be a no-op, depending on the stream.
-
Flushes disk buffers to disk (
fsync
) -
Closes the file.
Mixins
impl File { ... }
-
mixin FdReadWrite<File>
-
Reads from the stream into a provided buffer.
If successful, returns the number of bytes read. This may be less than the size of the provided buffer.
-
Write the buffer to the stream.
Returns the number of bytes written. This may be less than the size of the buffer. See also write_all, which can be used to write the entire buffer.
-
-
Fills the provided buffer by reading from the stream.
If stream had less bytes available than the size of the buffer, this method will return an
Error::eof()
. -
Reads the entire stream into a
StringBuf
.If successful, returns the number of bytes that were read.
-
-
Writes all the bytes in the buffer to the stream.
If EOF is reached, returns
Error::eof()
. -
-
Rewind the stream to the beginning.
-
Returns the current position in the stream from the beginning.