xtd - Reference Guide 0.2.0
xtd::io::file Class Reference

#include <file.h>

## Definition

Provides static methods for the creation, copying, deletion, moving, and opening of files, and aids in the creation of std::fstream objects.

class core_export_ file static_
Inheritance
xtd::static_objectxtd::io::file
Namespace
xtd::io
Library
xtd.core

## Methods

template<typename type_t >
static void append_all_lines (const xtd::ustring &path, type_t contents)
Appends lines to a file, and then closes the file. If the specified file does not exist, this method creates a file, writes the specified lines to the file, and then closes the file. More...

template<typename type_t >
static void append_all_lines (const xtd::ustring &path, const std::initializer_list< type_t > &contents)
Appends lines to a file, and then closes the file. If the specified file does not exist, this method creates a file, writes the specified lines to the file, and then closes the file. More...

template<typename type_t >
static void append_all_text (const xtd::ustring &path, type_t text)
Appends text to a file, and then closes the file. If the specified file does not exist, this method creates a file, writes the specified lines to the file, and then closes the file. More...

static std::ofstream append_text (const xtd::ustring &path)
Creates a std::ofstream that appends text to an existing file. More...

static void copy (const xtd::ustring &src, const xtd::ustring &dest)
Copies an existing file to a new file. Overwriting a file of the same name is not allowed. More...

static void copy (const xtd::ustring &src, const xtd::ustring &dest, bool overwrite)
Copies an existing file to a new file. Overwriting a file of the same name is allowed. More...

static std::ofstream create (const xtd::ustring &path)
Creates or overwrites a file in the specified path. More...

static std::ofstream create_text (const xtd::ustring &path)
Creates or opens a file for writing text. More...

static bool exists (const xtd::ustring &path) noexcept
Determines whether the specified file exists. More...

static xtd::io::file_attributes get_attributes (const xtd::ustring &path)
Gets the xtd::io::file_attributes of the file on the path. More...

static xtd::date_time get_creation_time (const xtd::ustring &path)
Returns the creation date and time of the specified file or directory. More...

static xtd::date_time get_last_access_time (const xtd::ustring &path)
Returns the date and time the specified file or directory was last accessed. More...

static xtd::date_time get_last_write_time (const xtd::ustring &path)
Returns the date and time the specified file or directory was last written to. More...

static xtd::io::file_permissions get_permissions (const xtd::ustring &path)
Gets the xtd::io::file_permissions of the file on the path. More...

static void move (const xtd::ustring &src, const xtd::ustring &dest)
Moves a specified file to a new location, providing the option to specify a new file name. More...

static void move (const xtd::ustring &src, const xtd::ustring &dest, bool overwrite)
Moves a specified file to a new location, providing the options to specify a new file name and to overwrite the destination file if it already exists. More...

static std::fstream open (const xtd::ustring &path, std::ios::openmode mode)
Opens a FileStream on the specified path. More...

static std::ifstream open_read (const xtd::ustring &path)
Opens an existing file for reading. More...

static std::ifstream open_text (const xtd::ustring &path)
Opens an existing file for reading. More...

static std::ofstream open_write (const xtd::ustring &path)
Opens an existing file for writing. More...

static std::vector< uint8_t > read_all_bytes (const xtd::ustring &path)
Opens a binary file, reads the contents of the file into a byte array, and then closes the file. More...

template<typename char_t >
static std::vector< uint8_t > read_all_bytes (const char_t *path)
Opens a binary file, reads the contents of the file into a byte array, and then closes the file. More...

static std::vector< xtd::ustringread_all_lines (const xtd::ustring &path)
Opens a text file, reads all lines of the file, and then closes the file. More...

static xtd::ustring read_all_text (const xtd::ustring &path)
Opens a text file, reads all text of the file, and then closes the file. More...

static void remove (const xtd::ustring &path)
Deletes the specified file. More...

static void replace (const xtd::ustring &source_file_name, const xtd::ustring &destination_file_name, const xtd::ustring &destination_backup_file_name)
Replaces the contents of a specified file with the contents of another file, deleting the original file, and creating a backup of the replaced file and optionally ignores merge errors. More...

static void set_attributes (const xtd::ustring &path, xtd::io::file_attributes attributes)
Sets the specified xtd::io::file_attributes of the file on the specified path. More...

static void set_creation_time (const xtd::ustring &path, const xtd::date_time &creation_time)
Sets the date and time the file was created. More...

static void set_last_access_time (const xtd::ustring &path, const xtd::date_time &last_access_time)
Sets the date and time the specified file was last accessed. More...

static void set_last_write_time (const xtd::ustring &path, const xtd::date_time &last_write_time)
Sets the date and time that the specified file was last written to. More...

static void set_permissions (const xtd::ustring &path, xtd::io::file_permissions permissions)
Sets the specified xtd::io::file_permissions of the file on the specified path. More...

template<typename type_t >
static void write_all_lines (const xtd::ustring &path, type_t contents)
Writes lines to a file, and then closes the file. If the specified file does not exist, this method creates a file, writes the specified lines to the file, and then closes the file. More...

template<typename type_t >
static void write_all_lines (const xtd::ustring &path, const std::initializer_list< type_t > &contents)
Writes lines to a file, and then closes the file. If the specified file does not exist, this method creates a file, writes the specified lines to the file, and then closes the file. More...

template<typename type_t >
static void write_all_text (const xtd::ustring &path, type_t text)
Writes text to a file, and then closes the file. If the specified file does not exist, this method creates a file, writes the specified lines to the file, and then closes the file. More...

static std::ofstream write_text (const xtd::ustring &path)
Creates a std::ofstream that appends text to an existing file. More...

## ◆ append_all_lines() [1/2]

template<typename type_t >
 static void xtd::io::file::append_all_lines ( const xtd::ustring & path, type_t contents )
inlinestatic

Appends lines to a file, and then closes the file. If the specified file does not exist, this method creates a file, writes the specified lines to the file, and then closes the file.

Parameters
 path The file to write to. contents The lines to append to the file.
Returns
true if the text appended; otherwise, false.
Exceptions
 xtd::argument_exception path contains one or more of the invalid characters -or- The system could not retrieve the absolute path. xtd::io::io_exception the handle of the specified file cannot be opened.
Remarks
If the target file already exists, it is overwritten.

## ◆ append_all_lines() [2/2]

template<typename type_t >
 static void xtd::io::file::append_all_lines ( const xtd::ustring & path, const std::initializer_list< type_t > & contents )
inlinestatic

Appends lines to a file, and then closes the file. If the specified file does not exist, this method creates a file, writes the specified lines to the file, and then closes the file.

Parameters
 path The file to write to. contents The lines to append to the file.
Returns
true if the text appended; otherwise, false.
Exceptions
 xtd::argument_exception path contains one or more of the invalid characters -or- The system could not retrieve the absolute path. xtd::io::io_exception the handle of the specified file cannot be opened.
Remarks
If the target file already exists, it is overwritten.

## ◆ append_all_text()

template<typename type_t >
 static void xtd::io::file::append_all_text ( const xtd::ustring & path, type_t text )
inlinestatic

Appends text to a file, and then closes the file. If the specified file does not exist, this method creates a file, writes the specified lines to the file, and then closes the file.

Parameters
 path The file to write to. contents The text to append to the file.
Returns
true if the text appended; otherwise, false.
Exceptions
 xtd::argument_exception path contains one or more of the invalid characters -or- The system could not retrieve the absolute path. xtd::io::io_exception the handle of the specified file cannot be opened.

## ◆ append_text()

 static std::ofstream xtd::io::file::append_text ( const xtd::ustring & path )
static

Creates a std::ofstream that appends text to an existing file.

Parameters
 path The path to the file to append to.
Returns
A std::ofstream that appends text to an existing file.
Exceptions
 xtd::argument_exception path contains one or more of the invalid characters -or- The system could not retrieve the absolute path. xtd::io::io_exception the handle of the specified file cannot be opened.

## ◆ copy() [1/2]

 static void xtd::io::file::copy ( const xtd::ustring & src, const xtd::ustring & dest )
static

Copies an existing file to a new file. Overwriting a file of the same name is not allowed.

Parameters
 src The file to be opened for reading. dest The name of the destination file. This cannot be a directory or an existing file.
Exceptions
 xtd::argument_exception path contains one or more of the invalid characters -or- The system could not retrieve the absolute path. xtd::io::file_not_found_exception if file src does not exists. xtd::io::io_exception the handle of the specified file cannot be opened.

## ◆ copy() [2/2]

 static void xtd::io::file::copy ( const xtd::ustring & src, const xtd::ustring & dest, bool overwrite )
static

Copies an existing file to a new file. Overwriting a file of the same name is allowed.

Parameters
 src The file to be opened for reading. dest The name of the destination file. This cannot be a directory. overwrite true if the destination file can be overwritten; otherwise, false.
Exceptions
 xtd::argument_exception path contains one or more of the invalid characters -or- The system could not retrieve the absolute path -or- file dest exists. xtd::io::io_exception the handle of the specified file cannot be opened.

## ◆ create()

 static std::ofstream xtd::io::file::create ( const xtd::ustring & path )
static

Creates or overwrites a file in the specified path.

Parameters
 The path and name of the file to create.
Returns
Exceptions
 xtd::argument_exception path contains one or more of the invalid characters -or- The system could not retrieve the absolute path -or- file dest exists. xtd::io::io_exception the handle of the specified file cannot be created.

## ◆ create_text()

 static std::ofstream xtd::io::file::create_text ( const xtd::ustring & path )
static

Creates or opens a file for writing text.

Creates or overwrites a file in the specified path.

Parameters
 The path and name of the file to create.
Returns
Exceptions
 xtd::argument_exception path contains one or more of the invalid characters -or- The system could not retrieve the absolute path -or- file dest exists. xtd::io::io_exception the handle of the specified file cannot be created.

## ◆ exists()

 static bool xtd::io::file::exists ( const xtd::ustring & path )
staticnoexcept

Determines whether the specified file exists.

Parameters
 path The file to check.
Returns
true if the caller has the required permissions and path contains the name of an existing file; otherwise, false.
Remarks
This method also returns false if path is empty or an invalid path.
If the caller does not have sufficient permissions to read the specified file, no exception is thrown and the method returns false regardless of the existence of path.

## ◆ get_attributes()

 static xtd::io::file_attributes xtd::io::file::get_attributes ( const xtd::ustring & path )
static

Gets the xtd::io::file_attributes of the file on the path.

Parameters
 path The path to the file.
Returns
The xtd::io::file_attributes of the file on the path.
Exceptions
 xtd::io::file_not_found_exception if file src does not exists.

## ◆ get_creation_time()

 static xtd::date_time xtd::io::file::get_creation_time ( const xtd::ustring & path )
static

Returns the creation date and time of the specified file or directory.

Parameters
 path The file or directory for which to obtain creation date and time information.
Returns
A xtd::date_time class set to the creation date and time for the specified file or directory. This value is expressed in local time.
Exceptions
 xtd::unauthorized_access_exception The caller does not have the required permission. xtd::argument_exception path is a zero-length string, contains only white space, or contains one or more invalid characters. You can query for invalid characters by using the xtd::path::get_invalid_path_chars method. xtd::io::path_too_long_exception The specified path, file name, or both exceed the system-defined maximum length. xtd::not_supported_excpttion path is in an invalid format.

## ◆ get_last_access_time()

 static xtd::date_time xtd::io::file::get_last_access_time ( const xtd::ustring & path )
static

Returns the date and time the specified file or directory was last accessed.

Parameters
 path The file or directory for which to obtain access date and time information.
Returns
A xtd::date_time structure set to the date and time that the specified file or directory was last accessed. This value is expressed in local time.
Exceptions
 xtd::unauthorized_access_exception The caller does not have the required permission. xtd::argument_exception path is a zero-length string, contains only white space, or contains one or more invalid characters. You can query for invalid characters by using the xtd::path::get_invalid_path_chars method. xtd::io::path_too_long_exception The specified path, file name, or both exceed the system-defined maximum length. xtd::not_supported_excpttion path is in an invalid format.

## ◆ get_last_write_time()

 static xtd::date_time xtd::io::file::get_last_write_time ( const xtd::ustring & path )
static

Returns the date and time the specified file or directory was last written to.

Parameters
 path The file or directory for which to obtain write date and time information.
Returns
A xtd::date_time structure set to the date and time that the specified file or directory was last written to. This value is expressed in local time.
Exceptions
 xtd::unauthorized_access_exception The caller does not have the required permission. xtd::argument_exception path is a zero-length string, contains only white space, or contains one or more invalid characters. You can query for invalid characters by using the xtd::path::get_invalid_path_chars method. xtd::io::path_too_long_exception The specified path, file name, or both exceed the system-defined maximum length. xtd::not_supported_excpttion path is in an invalid format.

## ◆ get_permissions()

 static xtd::io::file_permissions xtd::io::file::get_permissions ( const xtd::ustring & path )
static

Gets the xtd::io::file_permissions of the file on the path.

Parameters
 path The path to the file.
Returns
The xtd::io::file_permissions of the file on the path.
Exceptions
 xtd::io::file_not_found_exception if file src does not exists.

## ◆ move() [1/2]

 static void xtd::io::file::move ( const xtd::ustring & src, const xtd::ustring & dest )
static

Moves a specified file to a new location, providing the option to specify a new file name.

Parameters
 src The name of the file to move. dest The new path for the file.
Returns
true if the file moved; otherwise, false.
Exceptions
 xtd::argument_exception if dest already exist. xtd::io::io_exception if path is empty or an invalid path. xtd::io::io_exception if the caller has not the required permissions.

## ◆ move() [2/2]

 static void xtd::io::file::move ( const xtd::ustring & src, const xtd::ustring & dest, bool overwrite )
static

Moves a specified file to a new location, providing the options to specify a new file name and to overwrite the destination file if it already exists.

Parameters
 src The name of the file to move. dest The new path for the file. overwrite true to overwrite the destination file if it already exists; false otherwise.
Returns
true if the file moved; otherwise, false.
Exceptions
 xtd::argument_exception if dest already exist. xtd::io::io_exception if path is empty or an invalid path. xtd::io::io_exception if the caller has not the required permissions.

## ◆ open()

 static std::fstream xtd::io::file::open ( const xtd::ustring & path, std::ios::openmode mode )
static

Opens a FileStream on the specified path.

Parameters
 path The file to open. mode A std::ios::openmode value that specifies whether a file is created if one does not exist, and determines whether the contents of existing files are retained or overwritten.
Returns
A std::fstream on the specified path.
Exceptions
 xtd::argument_exception path contains one or more of the invalid characters -or- The system could not retrieve the absolute path. xtd::io::io_exception the handle of the specified file cannot be opened.

 static std::ifstream xtd::io::file::open_read ( const xtd::ustring & path )
static

Opens an existing file for reading.

Parameters
 path The file to be opened for reading.
Returns
A std::ifstream on the specified path.
Exceptions
 xtd::argument_exception path contains one or more of the invalid characters -or- The system could not retrieve the absolute path. xtd::io::io_exception the handle of the specified file cannot be opened.

## ◆ open_text()

 static std::ifstream xtd::io::file::open_text ( const xtd::ustring & path )
static

Opens an existing file for reading.

Parameters
 path The file to be opened for reading.
Returns
A std::ifstream on the specified path.
Exceptions
 xtd::argument_exception path contains one or more of the invalid characters -or- The system could not retrieve the absolute path. xtd::io::io_exception the handle of the specified file cannot be opened.

## ◆ open_write()

 static std::ofstream xtd::io::file::open_write ( const xtd::ustring & path )
static

Opens an existing file for writing.

Parameters
 path The file to be opened for writing.
Returns
A std::ofstream on the specified path.
Exceptions
 xtd::argument_exception path contains one or more of the invalid characters -or- The system could not retrieve the absolute path. xtd::io::io_exception the handle of the specified file cannot be opened.

 static std::vector xtd::io::file::read_all_bytes ( const xtd::ustring & path )
static

Opens a binary file, reads the contents of the file into a byte array, and then closes the file.

Parameters
 path The file to open for reading.
Returns
A byte array containing the contents of the file.
Exceptions
 xtd::io::file_not_found_exception if path does not exists. xtd::argument_exception path contains one or more of the invalid characters -or- The system could not retrieve the absolute path. xtd::io::io_exception the handle of the specified file cannot be opened.

template<typename char_t >
 static std::vector xtd::io::file::read_all_bytes ( const char_t * path )
inlinestatic

Opens a binary file, reads the contents of the file into a byte array, and then closes the file.

Parameters
 path The file to open for reading.
Returns
A byte array containing the contents of the file.
Exceptions
 xtd::io::file_not_found_exception if path does not exists. xtd::argument_exception path contains one or more of the invalid characters -or- The system could not retrieve the absolute path. xtd::io::io_exception the handle of the specified file cannot be opened.

 static std::vector xtd::io::file::read_all_lines ( const xtd::ustring & path )
static

Opens a text file, reads all lines of the file, and then closes the file.

Parameters
 path The file to open for reading.
Returns
A String array containing all lines of the file.
Remarks
This method also returns an empty array if path is empty or an invalid path.
If the caller does not have sufficient permissions to read the specified file, no exception is thrown and the method returns an empty array regardless of the existence of path.

 static xtd::ustring xtd::io::file::read_all_text ( const xtd::ustring & path )
static

Opens a text file, reads all text of the file, and then closes the file.

Parameters
 path The file to open for reading.
Returns
A string containing all text of the file.
Remarks
This method also returns empty string if path is empty or an invalid path.
If the caller does not have sufficient permissions to read the specified file, no exception is thrown and the method returns empty string regardless of the existence of file.

## ◆ remove()

 static void xtd::io::file::remove ( const xtd::ustring & path )
static

Deletes the specified file.

Parameters
 path The name of the file to be deleted.
Returns
std::ofstream An unshared std::ofstream that provides access to the specified file, with the specified mode and access.
true if the file is deleted; otherwise, false.

## ◆ replace()

 static void xtd::io::file::replace ( const xtd::ustring & source_file_name, const xtd::ustring & destination_file_name, const xtd::ustring & destination_backup_file_name )
static

Replaces the contents of a specified file with the contents of another file, deleting the original file, and creating a backup of the replaced file and optionally ignores merge errors.

Parameters
 source_file_name The name of a file that replaces the file specified by destination_file_name. destination_file_name The name of the file being replaced. destination_backup_file_name The name of the backup file. ignore_metadata_errors true to ignore merge errors (such as attributes and access control lists (ACLs)) from the replaced file to the replacement file; otherwise, false.
Returns
false source_file_name does not exist or bad format, or destination_file_name does not exist or bad format, or if ignore_metadata_errors equal false and destination_backup_file_name bad format or on ani io error; otherwise true.

## ◆ set_attributes()

 static void xtd::io::file::set_attributes ( const xtd::ustring & path, xtd::io::file_attributes attributes )
static

Sets the specified xtd::io::file_attributes of the file on the specified path.

Parameters
 path The path to the file. attributes A bitwise combination of the enumeration values.
Exceptions
 xtd::io::io_exception The file specified by path is a directory. xtd::argument_exception path is a zero-length string, contains only white space, or contains one or more invalid characters. You can query for invalid characters by using the xtd::io::path::get_invalid_path_chars method. xtd::io::path_too_long_exception The specified path, file name, or both exceed the system-defined maximum length. xtd::io::file_not_found_exception The specified path is invalid (for example, it is on an unmapped drive). xtd::not_supported_exception path contains a colon character (:) that is not part of a drive label ("C:\").
Remarks
The path parameter is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see xtd::io::directory::get_current_directory.
Certain file attributes, such as xtd::io::file_attributes::hidden and xtd::io::file_attributes::read_only, can be combined. Other attributes, such as xtd::io::file_attributes::normal, must be used alone.
It is not possible to change the compression status of a xtd::io::file object using the xtd::io::file::set_attributes method.

## ◆ set_creation_time()

 static void xtd::io::file::set_creation_time ( const xtd::ustring & path, const xtd::date_time & creation_time )
static

Sets the date and time the file was created.

Parameters
 path The file for which to set the creation date and time information. creation_time A xtd::date_time containing the value to set for the creation date and time of path. This value is expressed in local time.
Exceptions
 xtd::io::io_exception The file specified by path is a directory. xtd::argument_exception path is a zero-length string, contains only white space, or contains one or more invalid characters. You can query for invalid characters by using the xtd::io::path::get_invalid_path_chars method. xtd::io::path_too_long_exception The specified path, file name, or both exceed the system-defined maximum length. xtd::io::file_not_found_exception The specified path is invalid (for example, it is on an unmapped drive). xtd::not_supported_exception path contains a colon character (:) that is not part of a drive label ("C:\").
Remarks
The path parameter is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see xtd::io::directory::get_current_directory.
NTFS-formatted drives may cache file meta-info, such as file creation time, for a short period of time. As a result, it may be necessary to explicitly set the creation time of a file if you are overwriting or replacing an existing file.

## ◆ set_last_access_time()

 static void xtd::io::file::set_last_access_time ( const xtd::ustring & path, const xtd::date_time & last_access_time )
static

Sets the date and time the specified file was last accessed.

Parameters
 path The file for which to set the access date and time information. last_access_time A xtd::date_time containing the value to set for the last access date and time of path. This value is expressed in local
Exceptions
 xtd::io::io_exception The file specified by path is a directory. xtd::argument_exception path is a zero-length string, contains only white space, or contains one or more invalid characters. You can query for invalid characters by using the xtd::io::path::get_invalid_path_chars method. xtd::io::path_too_long_exception The specified path, file name, or both exceed the system-defined maximum length. xtd::io::file_not_found_exception The specified path is invalid (for example, it is on an unmapped drive). xtd::not_supported_exception path contains a colon character (:) that is not part of a drive label ("C:\").
Remarks
The path parameter is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see xtd::io::directory::get_current_directory.

## ◆ set_last_write_time()

 static void xtd::io::file::set_last_write_time ( const xtd::ustring & path, const xtd::date_time & last_write_time )
static

Sets the date and time that the specified file was last written to.

Parameters
 path The file for which to set the date and time information. last_write_time A xtd::date_time containing the value to set for the last write date and time of path. This value is expressed in local time.
Exceptions
 xtd::io::io_exception The file specified by path is a directory. xtd::argument_exception path is a zero-length string, contains only white space, or contains one or more invalid characters. You can query for invalid characters by using the xtd::io::path::get_invalid_path_chars method. xtd::io::path_too_long_exception The specified path, file name, or both exceed the system-defined maximum length. xtd::io::file_not_found_exception The specified path is invalid (for example, it is on an unmapped drive). xtd::not_supported_exception path contains a colon character (:) that is not part of a drive label ("C:\").
Remarks
The path parameter is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see xtd::io::directory::get_current_directory.

## ◆ set_permissions()

 static void xtd::io::file::set_permissions ( const xtd::ustring & path, xtd::io::file_permissions permissions )
static

Sets the specified xtd::io::file_permissions of the file on the specified path.

Parameters
 path The path to the file. attributes A bitwise combination of the enumeration values.
Exceptions
 xtd::io::io_exception The file specified by path is a directory. xtd::argument_exception path is a zero-length string, contains only white space, or contains one or more invalid characters. You can query for invalid characters by using the xtd::io::path::get_invalid_path_chars method. xtd::io::path_too_long_exception The specified path, file name, or both exceed the system-defined maximum length. xtd::io::file_not_found_exception The specified path is invalid (for example, it is on an unmapped drive). xtd::not_supported_exception path contains a colon character (:) that is not part of a drive label ("C:\").
Remarks
The path parameter is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see xtd::io::directory::get_current_directory.

## ◆ write_all_lines() [1/2]

template<typename type_t >
 static void xtd::io::file::write_all_lines ( const xtd::ustring & path, type_t contents )
inlinestatic

Writes lines to a file, and then closes the file. If the specified file does not exist, this method creates a file, writes the specified lines to the file, and then closes the file.

Parameters
 path The file to write to. contents The lines to write to the file.
Returns
true if the text written; otherwise, false.
Exceptions
 xtd::argument_exception path contains one or more of the invalid characters -or- The system could not retrieve the absolute path. xtd::io::io_exception the handle of the specified file cannot be opened.
Remarks
If the target file already exists, it is overwritten.

## ◆ write_all_lines() [2/2]

template<typename type_t >
 static void xtd::io::file::write_all_lines ( const xtd::ustring & path, const std::initializer_list< type_t > & contents )
inlinestatic

Writes lines to a file, and then closes the file. If the specified file does not exist, this method creates a file, writes the specified lines to the file, and then closes the file.

Parameters
 path The file to write to. contents The lines to write to the file.
Returns
true if the text written; otherwise, false.
Exceptions
 xtd::argument_exception path contains one or more of the invalid characters -or- The system could not retrieve the absolute path. xtd::io::io_exception the handle of the specified file cannot be opened.
Remarks
If the target file already exists, it is overwritten.

## ◆ write_all_text()

template<typename type_t >
 static void xtd::io::file::write_all_text ( const xtd::ustring & path, type_t text )
inlinestatic

Writes text to a file, and then closes the file. If the specified file does not exist, this method creates a file, writes the specified lines to the file, and then closes the file.

Parameters
 path The file to write to. contents The text to write to the file.
Returns
true if the text written; otherwise, false.
Exceptions
 xtd::argument_exception path contains one or more of the invalid characters -or- The system could not retrieve the absolute path. xtd::io::io_exception the handle of the specified file cannot be opened.

## ◆ write_text()

 static std::ofstream xtd::io::file::write_text ( const xtd::ustring & path )
static

Creates a std::ofstream that appends text to an existing file.

Parameters
 path The path to the file to write to.
Returns
A std::ofstream that writes text to an existing file.
Exceptions
 xtd::argument_exception path contains one or more of the invalid characters -or- The system could not retrieve the absolute path. xtd::io::io_exception the handle of the specified file cannot be opened.

The documentation for this class was generated from the following file:
• xtd.core/include/xtd/io/file.h