LibGDX没有使用Android资源文件夹

我在编译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(); } 

抛出未找到文件的exception。 我的文件夹结构如下:

 -Android -assets -gameMap.txt -Desktop -IOS -HTML -core 

如果您使用的是Android Studio,请选择编辑配置… 如果您使用的是Android Studio,请选择编辑配置...

将“桌面应用程序” – >“工作目录”更改为您的android资产forlder 将“桌面应用程序” -/>“工作目录”更改为您的android资产forlder”></p>

</div><!-- #comment-## -->
<div class=

你应该使用Gdx.file.internal();

https://github.com/libgdx/libgdx/wiki/File-handling#reading-from-a-file

如果您使用[设置UI | 项目设置,运行和调试],这个文件将包含在Android项目的资产文件夹中,确切地说是$ ANDROID_PROJECT / assets / data。 您的桌面和html项目链接到Eclipse中的此文件夹,并在Eclipse中执行时自动选择它。