File
struct File
Methods
write_byte
pub fn write_byte(self, byte: int) throws IoError
Write a byte (u8) to the fs.
write_byte
pub fn write_byte(self, byte: int) throws IoError
Write a byte (u8) to the fs.
Write a byte (u8) to the fs.
The element must be in the range 0..255, if not, it will panic.
nv,
use std.fs.File;
fn main() throws {
let f = try File.create("foo.txt");
try f.write_byte(72);
try f.write_byte(101);
}
Opens a file in write-only mode, and return a File
type.
Opens a file in write-only mode, and return a File
type.
Opens a file in write-only mode, and return a File
type.
This function will create a file if it does not exist, and will truncate it if it does.
nv,
use std.fs.File;
fn main() throws {
let f = try File.create("foo.txt");
try f.write_string("Hello, world!");
}
Open a file, and return a File
type, default is read-only mode.
Open a file, and return a File
type, default is read-only mode.
Open a file, and return a File
type, default is read-only mode.
Arguments
flag
- The flag to open the file, default isREAD
in read-only mode, supported flags are:READ
,WRITE
,APPEND
,TRUNCATE
,CREATE
,CREATE_NEW
.mode
- The mode to open the file, default is0o666
.
nv,
use std.fs.{self, File};
fn main() throws {
let f = try File.open("foo.txt");
let s = try f.read_to_string();
// => "Hello, world!"
let f = try File.open("foo.txt", flag: fs.READ|fs.WRITE, mode: 0o644);
let s = try f.read_to_string();
// => "Hello, world!"
try f.write("This is new contents".bytes());
let s = try f.read_to_string();
// => "This is new contents"
}