# Read file from Elasticsearch plugin

**URL:** <https://discuss.elastic.co/t/read-file-from-elasticsearch-plugin/160374>\
**Category:** Elasticsearch\
**Created:** [December 11, 2018, 12:08pm UTC](https://discuss.elastic.co/t/read-file-from-elasticsearch-plugin/160374 "2018-12-11T12:08:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Uiidoi12](https://avatars.discourse-cdn.com/v4/letter/u/73ab20/32.png) [@Uiidoi12](https://discuss.elastic.co/u/Uiidoi12)\
**Post date:** [December 11, 2018, 12:08pm UTC](https://discuss.elastic.co/t/read-file-from-elasticsearch-plugin/160374/1 "2018-12-11T12:08:09Z")

</div>

Hi,

I'm trying to read a file inside my custom plugin like this:

```java
JsonReader reader = new JsonReader(new FileReader(getClass().getClassLoader().getResource(
            "myplugin/es/plugin/file.json").getFile()));

```

but I got:

```auto
access denied (\"java.io.FilePermission\" \"file:/usr/share/elasticsearch/plugins/myplugin/myplugin-1.0.0.jar!/myplugin/es/plugin/file.json\" \"read\"

```

I tried to add:

```auto
permission java.io.FilePermission "/usr/share/elasticsearch/plugins/myplugin/*", "read,write";

```

or

```auto
permission java.io.FilePermission "*", "read,write";`

```

to my `plugin-security.policy` file, but same error.

Any help please?

Thanks.  
Regards

---

<div class="post-metadata">

**Author:** ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)\
**Post date:** [December 11, 2018, 10:10pm UTC](https://discuss.elastic.co/t/read-file-from-elasticsearch-plugin/160374/2 "2018-12-11T22:10:48Z")

</div>

All plugins automatically have permission to read their own jars. The problem is by trying to read this as a file directly, you have a path which is not given permission. Instead, try reading the resource as an InputStream:

```auto
JsonReader reader = new JsonReader(
    new InputStreamReader(getClass().getResourceAsStream("/myplugin/es/plugin/file.json"), StandardCharsets.UTF_8)));

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [January 8, 2019, 10:10pm UTC](https://discuss.elastic.co/t/read-file-from-elasticsearch-plugin/160374/3 "2019-01-08T22:10:50Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
