# getResource() idiosyncracy

**URL:** https://discourse.processing.org/t/getresource-idiosyncracy/45356
**Category:** Coding Questions
**Created:** [November 18, 2024, 5:22pm UTC](https://discourse.processing.org/t/getresource-idiosyncracy/45356 "2024-11-18T17:22:01Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)
#### Post date: [November 18, 2024, 5:22pm UTC](https://discourse.processing.org/t/getresource-idiosyncracy/45356/1 "2024-11-18T17:22:01Z")

</div>

When porting java code to Processing sometimes it is necessary to use _getResource()_ even though Processing does not have a ‘_resources_’ folder. In order to get a valid url in the following demo it is necessary to have the desired file lying free in the sketch folder as well as a copy of the file in a folder named ‘code’. There is an alternative work around by first getting a url from the file path string and then converting it back to a string. The second method is more code but will work on a single copy of the file in the sketch folder. Are there any other options that I am unaware of?

```auto
/*
 Requires one copy of the file lying free in the sketch folder
 and another copy of the file in a folder named 'code'
*/

import java.net.URL;

void setup() {
  String path = sketchPath() + "/myFile.txt";
  URL url = getClass().getResource(path);
  println("url =",url);
}

```

 ![rsrc](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/6/a/6a7921b1f3d690a62d21c30eadae83f57cce3724.png)
