Question: I'm trying to unmarshal my xml file:

```
public Object convertFromXMLToObject(String xmlfile) throws IOException {
    FileInputStream is = null;
    File file = new File(String.valueOf(this.getClass().getResource("xmlToParse/companies.xml")));
    try {
        is = new FileInputStream(file);
        return getUnmarshaller().unmarshal(new StreamSource(is));
    } finally {
        if (is != null) {
            is.close();
        }
    }
}

```

But I get this errors:
java.io.FileNotFoundException: null (No such file or directory)

Here is my structure:

[![enter image description here](https://i.stack.imgur.com/nfhZa.png)](https://i.stack.imgur.com/nfhZa.png)

Why I can't get files from resources folder? Thanks.

**Update.**

After refactoring,

URL url = this.getClass().getResource("/xmlToParse/companies.xml");
 File file = new File(url.getPath());

I can see an error more clearly:

java.io.FileNotFoundException: /content/ROOT.war/WEB-INF/classes/xmlToParse/companies.xml (No such file or directory)

It tries to find WEB-INF/classes/ 
I have added folder there, but still get this error :(

[![enter image description here](https://i.stack.imgur.com/8UQ7s.png)](https://i.stack.imgur.com/8UQ7s.png)

Answer: 
```
ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource("fileName").getFile());

```
you are suppose to give an absolute path (so add a loading ´/´, where resource-folder is the root-folder):

```
public Object convertFromXMLToObject(String xmlfile) throws IOException {
    FileInputStream is = null;
    File file = new File(String.valueOf(this.getClass().getResource("/xmlToParse/companies.xml")));
    try {
        is = new FileInputStream(file);
        return getUnmarshaller().unmarshal(new StreamSource(is));
    } finally {
        if (is != null) {
            is.close();
        }
    }
}

```