# Expose files to the system?

**URL:** <https://forum.inductiveautomation.com/t/expose-files-to-the-system/48008>\
**Category:** Module Development\
**Created:** [June 21, 2021, 10:53am UTC](https://forum.inductiveautomation.com/t/expose-files-to-the-system/48008 "2021-06-21T10:53:31Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![mlunapinel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mlunapinel/32/19719_2.png) [@mlunapinel](https://forum.inductiveautomation.com/u/mlunapinel)\
**Post date:** [June 21, 2021, 10:53am UTC](https://forum.inductiveautomation.com/t/expose-files-to-the-system/48008/1 "2021-06-21T10:53:31Z")

</div>

Hello!

I am trying to open a html file from an ActionPerformed of a jButton in the designer as follows:

```auto
File html = new File("Path/To/File");
if(Desktop.isDesktopSupported()){
     Desktop.getDesktop().browse(html.toURI());
}else{
     logger.info("Not supported");
}

```

The problem is, how can the system find the file? I have tried in the Designer’s Resource folder with no luck. I’m having the same problem with images to generate ImageIcons.

Thanks in advance,

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [June 21, 2021, 11:53am UTC](https://forum.inductiveautomation.com/t/expose-files-to-the-system/48008/2 "2021-06-21T11:53:09Z")

</div>

Where is the file? In the module? If a resource in your module’s jar(s), you’ll have to extract the resource into a temporary file and pass that path to the external process.

---

<div class="post-metadata">

**Author:** ![mlunapinel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mlunapinel/32/19719_2.png) [@mlunapinel](https://forum.inductiveautomation.com/u/mlunapinel)\
**Post date:** [June 21, 2021, 12:06pm UTC](https://forum.inductiveautomation.com/t/expose-files-to-the-system/48008/3 "2021-06-21T12:06:41Z")

</div>

The file would be in the module, yes. Would you mind elaborating on how to extract the temporary file?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [June 21, 2021, 12:26pm UTC](https://forum.inductiveautomation.com/t/expose-files-to-the-system/48008/4 "2021-06-21T12:26:41Z")

</div>

You use the classloader for the class the file is alongside and open the resource as a stream:

[https://docs.oracle.com/javase/8/docs/api/java/lang/ClassLoader.html#getResourceAsStream-java.lang.String-](https://docs.oracle.com/javase/8/docs/api/java/lang/ClassLoader.html#getResourceAsStream-java.lang.String-)

Then I’d create and open a temporary file and use IOUtils.copy() to fill the temporary file.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [June 21, 2021, 12:28pm UTC](https://forum.inductiveautomation.com/t/expose-files-to-the-system/48008/5 "2021-06-21T12:28:45Z")

</div>

For ImageIcon creation, I’d use findResource() to get the URL and then use the URL constructor. No need for a temporary file.

---

<div class="post-metadata">

**Author:** ![mlunapinel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mlunapinel/32/19719_2.png) [@mlunapinel](https://forum.inductiveautomation.com/u/mlunapinel)\
**Post date:** [June 21, 2021, 12:29pm UTC](https://forum.inductiveautomation.com/t/expose-files-to-the-system/48008/6 "2021-06-21T12:29:00Z")

</div>

Okay, I think I got it. Thanks!

---

<div class="post-metadata">

**Author:** ![mlunapinel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mlunapinel/32/19719_2.png) [@mlunapinel](https://forum.inductiveautomation.com/u/mlunapinel)\
**Post date:** [June 23, 2021, 4:09pm UTC](https://forum.inductiveautomation.com/t/expose-files-to-the-system/48008/7 "2021-06-23T16:09:30Z")

</div>

If anyone is ever wondering how to do this:

```auto
public void readAndOpenHTML()
            throws IOException {
        ClassLoader classLoader = this.getClass().getClassLoader();
        InputStream is = classLoader.getResourceAsStream("nameOftheResource.html");
        byte[] buffer = new byte[is.available()];
        is.read(buffer);
        is.close();
        Path tmpPath= Files.createTempFile("temporalName",".html");
        File html = tmpPath.toFile();
        OutputStream os = new FileOutputStream(html);
        os.write(buffer);;
        if (Desktop.isDesktopSupported()) {
            new Thread(()-> {
                try {
                    Desktop.getDesktop().browse(html.toURI());
                } catch (IOException e) {
                    //e.printStackTrace();
                    log.info("IOEX");
                    log.info(e.toString());
                }catch (Exception e){

                }
            }).start();
        } else {
            log.info("Desktop browser not suported");
        }

        os.close();

    }

```

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [June 23, 2021, 7:07pm UTC](https://forum.inductiveautomation.com/t/expose-files-to-the-system/48008/8 "2021-06-23T19:07:55Z")

</div>

Consider caching the temporary file names to allow re-use if still there on future access.

---

<div class="post-metadata">

**Author:** ![mlunapinel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mlunapinel/32/19719_2.png) [@mlunapinel](https://forum.inductiveautomation.com/u/mlunapinel)\
**Post date:** [June 23, 2021, 7:11pm UTC](https://forum.inductiveautomation.com/t/expose-files-to-the-system/48008/9 "2021-06-23T19:11:45Z")

</div>

Good point, thanks
