【发布时间】:2014-10-13 20:35:14
【问题描述】:
我在编译 Android 或 IOS 版本时遇到了读取 assets 文件夹的 libGDX 项目的问题。在尝试访问 android 模块下 assets 文件夹中的文件时,我似乎总是在 IOS 或 Android 中得到 FileNotFoundException,但在桌面上运行时却没有。我的桌面配置指向 android 资产目录,就像它应该的那样。
执行以下代码时:
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();
}
抛出未找到文件异常。我的文件夹结构如下:
-Android
-assets
-gameMap.txt
-Desktop
-IOS
-HTML
-core
【问题讨论】: