# fileOpen (Shared)

> Opens a file that already exists, with the position at its start.

- **Platform**: MY Multiplayer (MYMP)
- **Kind**: Lua Function
- **Side**: Shared
- **Category**: Files
- **URL**: https://wiki.mymp.gg/en/fileOpen

## Syntax

```lua
file|false fileOpen(string path [, bool readOnly = false])
```

## Parameters

| Name | Type | Description |
| --- | --- | --- |
| `path` | `string` | The path. A path inside the calling resource, or `@resource/path` for another resource's file. Another resource's file only opens with `readOnly`. |
| `readOnly` | `bool` | If `true`, the file opens for reading only. *(default: `false`)* |

## Returns

The open file, or `false` if it does not exist, is a folder or could not be opened.

A path may not contain `..`, `\` or `:`, nor start with `/`. Another resource's files can only be read; an invalid path logs a warning and the function returns `false`. The file is closed when the resource stops.

## Example

```lua
local file = fileOpen("@maps/spawns.json", true)
if file then
    local spawns = fromJSON(fileRead(file, fileGetSize(file)))
    fileClose(file)
end
```

## See also

- [fileCreate (Shared)](https://wiki.mymp.gg/en/fileCreate.md): Creates an empty file and opens it for reading and writing. A file that already exists is wiped and made again; missing folders are created.
- [fileRead (Shared)](https://wiki.mymp.gg/en/fileRead.md): Reads bytes from a file at the current position and moves the position on.
- [fileClose (Shared)](https://wiki.mymp.gg/en/fileClose.md): Closes a file, writing what is left, and destroys its element.
