I am having a problem with a libGDX project reading the assets folder when compiling the Android or IOS build. While trying to access a file in the assets folder under the android module, I always seem to get a FileNotFoundException in IOS or Android, but not when running it on the Desktop. My desktop config points the android asset directory like it should.
When executing the following code :
public void readGameMap() throws IOException
{
readGameMap("gameMap.txt");
}
public void readGameMap(String path) throws IOException
{
Scanner s = new Scanner(Gdx.files.internal(path).file());
int i = 0;
while ((s.hasNextLine()))
{
String str = s.nextLine();
if (str.length() < maze.length)
throw new IOException("Incorrect game_map.txt structure");
for (int j = 0; j < str.length(); j++)
{
Object temp;
switch (str.charAt(j))
{
case '1':
temp = new Wall();
break;
case '3':
temp = new Dot();
break;
default:
temp = new Object();
break;
}
maze[j][i] = temp;
}
i++;
}
s.close();
}
The file not found exception is thrown. My folder structure is as follows:
-Android
-assets
-gameMap.txt
-Desktop
-IOS
-HTML
-core
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…