I am using gradle for building 2D game project. I have set up gradle, but when I add images and txt files to resources folder I get FileNotFoundException: levels/level1_path.txt (No such file or directory).
I CAN NOT use GameEngine.class.getResource("levels/level1_path.txt").getFile() , because there are more than 100 pictures and icon in the game, it would be wrong. I need to find a way such that new File("levels/level1_path.txt") works.
My gradle :
plugins {
id 'java'
}
group 'org.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
sourceSets {
main {
resources {
srcDirs = ['src/main/resources']
}
}
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
// slick 2d
compile files('/Users/faridganbarli/Downloads/slickLIB/lib/jinput.jar')
compile files('/Users/faridganbarli/Downloads/slickLIB/lib/lwjgl.jar')
compile files('/Users/faridganbarli/Downloads/slickLIB/lib/lwjgl_util.jar')
compile files('/Users/faridganbarli/Downloads/slickLIB/lib/slick.jar')
}
My function :
private int[][] initLocations() throws FileNotFoundException{
File file = new File("levels/level1_path.txt");
Scanner sc = new Scanner(file);
int[][] loc=new int[sc.nextInt()][2];
for(int i=0; i<loc.length; i++){
loc[i][0]=sc.nextInt();
loc[i][1]=sc.nextInt();
}
return loc;
}