I have created a plugin. It needs to access 2 files from res folder. Now the trick here is, res folder is not inside plugin. For example, i have published plugin locally, so it now visible under any project you create, inside Tools Menu. What i want is, any new project i create, it will have 2 files facility.json & groups.json inside res folder, now my plugin should be able to access these files. I have tried different approach like as shown below, but it always fails, saying "File not found" exception. If anyone can help me out in this. Its appreciated. Thank you.
private static File getFileFromResource(String fileName) throws URISyntaxException {
ClassLoader classLoader = Validator.class.getClassLoader();
URL resource = classLoader.getResource(fileName);
if (resource == null) {
throw new IllegalArgumentException("file not found! " + fileName);
} else {
// failed if files have whitespaces or special characters
//return new File(resource.getFile());
return new File(resource.toURI());
}
}
private static InputStream getFileFromResourceAsStream(String fileName) {
// The class loader that loaded the class
ClassLoader classLoader = Validator.class.getClassLoader();
InputStream inputStream = classLoader.getResourceAsStream(fileName);
// the stream holding the file content
if (inputStream == null) {
throw new IllegalArgumentException("file not found! " + fileName);
} else {
return inputStream;
}
}