I tried to load file from resources folder but It throwed the exception :
java.io.FileNotFoundException: C:\PROJECTS%20FOR%20FOXMINDED\7%20TASK%20-%20SQL\target\classes\init.sql (The system cannot find the path specified)
The class where I tried to get file from resources :
public class FileLoader {
public File getFileFromResources(String fileName) {
ClassLoader classLoader = getClass().getClassLoader();
URL resource = classLoader.getResource(fileName);
if (resource == null) {
throw new IllegalArgumentException("file is not found!");
} else {
return new File(resource.getFile());
}
}
}
And in the Main.class I tried like this : File initializationDbSqlFile = fileLoader.getFileFromResources("init.sql");