Exception solved
Actually, when you write the metadata file, you want to save it into
"fileName(withoutExtension).json" but fileName gets the name of the
folder contained in filePath. It is looking for a folder in metadata
that does not exist...