Skip to content

Read a file as text

This article explains how to read a specific file as text data, and what to do when the data you read has garbled characters.

As a sample, here’s a flow that reads a text file saved in the Public Documents folder using the system’s default encoding (Shift_JIS on Japanese-language Windows).

Copy the following code and paste it into the Power Automate Desktop flow designer to add the action.

File.ReadTextFromFile.ReadText File: $'''C:\\Users\\Public\\Documents\\document.txt''' Encoding: File.TextFileEncoding.ANSI Content=> FileContents
  1. In “Search actions”, type “Read text from file” and set the parameters as follows.

    Parameter Value
    File path The path of the target file
    Store content as Choose whether to read the entire file as a single text value or each line as an item in a list
    Encoding The encoding of the file to read (the default is UTF-8)
  2. When you run the flow, the file’s data is stored as text in the produced variable (FileContents).

When the text you read has garbled characters

Section titled “When the text you read has garbled characters”

On Japanese-language Windows, the system’s default encoding (commonly called ANSI) is Shift_JIS (CP932, to be precise). On the other hand, files created on a Mac and much of the data retrieved from the web are saved in UTF-8.

The action for reading text from a file has a parameter called “Encoding” that specifies the character encoding. If the characters are garbled, this setting may not match the encoding of the target file.

Among the “Encoding” options, “ANSI” represents the system’s default encoding (Microsoft Learn lists it as “System default”; in the code, it appears as File.TextFileEncoding.ANSI). Choose it when you read a Shift_JIS file.

If the text is garbled with UTF-8, try switching to “ANSI”; if it’s garbled with “ANSI”, try “UTF-8”. This may fix the problem.