Como obter arquivos da pasta de recursos. Spring Framework
Estou tentando desfazer a análise do meu arquivo 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();
}
}
}
Mas eu recebo esses erros: java.io.FileNotFoundException: null (não existe esse arquivo ou diretório)
Aqui está a minha estrutura:
Por que não consigo obter arquivos da pasta de recursos? Obrigado.
Atualizar.
Após a refatoração,
URL URL = this.getClass (). GetResource ("/ xmlToParse / companies.xml"); Arquivo arquivo = novo arquivo (url.getPath ());
Eu posso ver um erro mais claramente:
java.io.FileNotFoundException: /content/ROOT.war/WEB-INF/classes/xmlToParse/companies.xml (Nenhum arquivo ou diretório desse tipo)
Ele tenta encontrar o WEB-INF / classes / eu adicionei a pasta lá, mas ainda assim obtém este erro :(