Read All Text from File
Description
The read_all_text
function reads the entire content of a text file and returns it as a string. It uses UTF-8 encoding to handle the file.
Function Signature:
def read_all_text(file_path: str) -> str:
Parameters
- file_path (str): Full path to the text file to be read.
Returns
- str: The content of the file as a string.
Example Usage
file_content = read_all_text("/path/to/text_file.txt")
print(file_content)
Notes
- The function opens the file in read mode with UTF-8 encoding.
- It returns the complete content of the file as a string.
Error Handling
- FileNotFoundError: Raised if the file does not exist.
- UnicodeDecodeError: Raised if the file cannot be decoded with UTF-8 encoding.