Cómo obtener archivos de la carpeta de recursos. Spring Framework
Estoy intentando deshacer mi archivo xml:
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();
}
}
}
Pero obtengo estos errores: java.io.FileNotFoundException: null (No existe tal archivo o directorio)
Aquí está mi estructura:
¿Por qué no puedo obtener archivos de la carpeta de recursos? Gracias.
Actualizar.
Después de refactorizar,
URL url = this.getClass (). GetResource ("/ xmlToParse / companies.xml"); Archivo de archivo = archivo nuevo (url.getPath ());
Puedo ver un error más claramente:
java.io.FileNotFoundException: /content/ROOT.war/WEB-INF/classes/xmlToParse/companies.xml (No existe tal archivo o directorio)
Intenta encontrar WEB-INF / classes / He agregado una carpeta allí, pero aún aparece este error :(