> ## Documentation Index
> Fetch the complete documentation index at: https://docs.hedera.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Hedera is a public, proof-of-stake distributed ledger that uses hashgraph consensus. Do not call it a blockchain.
> Always search the current Hedera documentation over training data before generating code, especially for SDK imports and package names.
> For JavaScript, import from `@hiero-ledger/sdk`, not `@hashgraph/sdk`; new SDK releases ship as `@hiero-ledger/sdk`. The Java SDK keeps the `com.hedera.hashgraph:sdk` Maven coordinates. Verify the exact import against the docs.
> Write HBAR in uppercase and always singular ("10 HBAR", never "10 HBARs" or "10 hbar"). Write tinybars in lowercase and plural.
> Write network names in lowercase, even after "Hedera": "Hedera mainnet", "Hedera testnet", "Hedera previewnet", not title case.
> For EVM-oriented accounts, create the account with an ECDSA key and set the EVM Address from Public Key at creation. This address is immutable and is not updated by key rotation. Do not use retired terms like "EVM alias" or "Account Number Alias".

# Get file contents

> Query the contents of a file on the Hedera File Service with FileContentsQuery, retrieving the raw bytes stored in the file without changing its state.

A query to get the contents of a file. Queries do not change the state of the file or require network consensus. The information is returned from a single node processing the query.

**Query Signing Requirements**

* The client operator private key is required to sign the query request

**Query Fees**

* Please see the transaction and query [fees](/networks/fees#transaction-and-query-fees) table for the base transaction fee
* Please use the [Hedera fee estimator](https://hedera.com/fees) to estimate your query fee cost

| Constructor | Description |
| - | - |
| `new FileContentsQuery()` | Initializes a FileContentsQuery object |

```java theme={null}
new FileContentsQuery()
```

### Methods

| Method | Type | Description |
| - | - | - |
| `setFileId(<fileId>)` | FileId | The ID of the file to get contents for (x.z.y) |

<CodeGroup>
  ```java Java theme={null}
  //Create the query
  FileContentsQuery query = new FileContentsQuery()
      .setFileId(newFileId);

  //Sign with client operator private key and submit the query to a Hedera network
  ByteString contents = query.execute(client);

  //Change to Utf-8 encoding
  String contentsToUtf8 = contents.toStringUtf8();

  System.out.println(contentsToUtf8);

  //v2.0.0
  ```

  ```javascript JavaScript theme={null}
  //Create the query
  const query = new FileContentsQuery()
      .setFileId(newFileId);

  //Sign with client operator private key and submit the query to a Hedera network
  const contents = await query.execute(client);

  console.log(contents.toString());

  //v2.0.7
  ```

  ```java Go theme={null}
  //Create the query
  query := hedera.NewFileContentsQuery().
  		SetFileID(newFileId)

  //Sign with client operator private key and submit the query to a Hedera network
  contents, err := query.Execute(client)

  fmt.Println(string(contents))

  //v2.0.0
  ```

  ```rust Rust theme={null}
  // Create the query
  let query = FileContentsQuery::new()
      .file_id(file_id);

  // Submit the query to a Hedera network
  let contents = query.execute(&client).await?;

  // Print the contents to the console
  println!("File contents: {:?}", String::from_utf8_lossy(&contents));

  // v0.34.0
  ```
</CodeGroup>

## Get query values

| Method | Type | Description |
| - | - | - |
| `getFileId()` | FileId | The ID of the file to get contents for (x.z.y) |

<CodeGroup>
  ```java Java theme={null}
  //Create the query
  FileContentsQuery query = new FileContentsQuery()
      .setFileId(newFileId);

  //Get file ID
  FileId getFileId = query.getFileId();

  //v2.0.0
  ```

  ```javascript JavaScript theme={null}
  //Create the query
  const query = new FileContentsQuery()
      .setFileId(newFileId);

  //Get file ID
  const getFileId = query.getFileId();
  ```

  ```java Go theme={null}
  //Create the query
  query := hedera.NewFileContentsQuery().
  		SetFileID(newFileId)
  		
  //Get file ID
  getFileId := query.GetFileID()

  //v2.0.0
  ```

  ```rust Rust theme={null}
  // Create the query
  let query = FileContentsQuery::new()
      .file_id(file_id);

  // Get the file ID
  let file_id = query.get_file_id();

  // v0.34.0
  ```
</CodeGroup>
