replace_contents
Description:
public bool replace_contents (uint8[] contents, string? etag, bool make_backup, FileCreateFlags flags, out string? new_etag, Cancellable? cancellable = null) throws Error
Example: Replace file-content (uint8[]-based), sync:
public static int main (string[] args) {
if (args.length != 2) {
print ("%s FILE\n", args[0]);
return 0;
}
try {
File file = File.new_for_commandline_arg (args[1]);
file.replace_contents ("My info\n".data, null, false, FileCreateFlags.NONE, null);
} catch (Error e) {
print ("Error: %s\n", e.message);
}
return 0;
}
valac --pkg gio-2.0 GLib.File.replace_contents.vala
Example: Replace content:
public static int main (string[] args) {
GLib.File file = GLib.File.new_for_commandline_arg (args[1]);
try {
file.replace_contents (args[0].data, null, true, GLib.FileCreateFlags.NONE, null, null);
} catch ( GLib.Error e ) {
GLib.error (e.message);
}
return 0;
}
valac --pkg gio-2.0 GLib.replace_contents.vala