简体   繁体   English

Android Java libgdx文本文件

[英]android Java libgdx text file

I'm having some trouble with loading and reading a text file in my android studio project. 我在Android Studio项目中加载和读取文本文件时遇到了一些麻烦。 When I run the desktop version it runs fine but when I run it on my phone (galaxy s4) through adb or packaging the app and manually installing it I get a blank black screen after my splash screens. 当我运行桌面版本时,它运行正常,但是当我通过adb在我的手机(银河s4)上运行它或打包应用程序并手动安装它时,启动画面后出现黑屏。 Through adb my logcat shows 通过adb我的logcat显示

W/System.err: Java.io.FileNotFoundException: /levels/1txt: open failed: ENOENT (No such file or directory) W / System.err:Java.io.FileNotFoundException:/ levels / 1txt:打开失败:ENOENT(无此类文件或目录)

My file is in the assets folder in a sub folder called levels. 我的文件位于子文件夹中的“资产”文件夹中。 The part of the code that flags the error is 代码中标记错误的部分是

String filePath = "levels/1.txt"; 字符串filePath =“ levels / 1.txt”; File filename = new File(filePath); File filename = new File(filePath);

The code after this uses scanner to read the file and put the characters in an array. 此后的代码使用扫描程序读取文件并将字符放入数组中。

I do wonder whether its my code thats wrong, my phone or my android studio setup(like it's not including my text file or something silly) 我确实想知道我的代码是否错误,我的手机还是我的android studio设置(例如它不包括我的文本文件或一些愚蠢的东西)

Sorry if this has been answered elsewhere. 抱歉,如果其他地方都回答了这个问题。 I was looking last night but didn't find anything that helped. 昨晚我一直在寻找,但没有找到任何帮助。

Thanks in advance for any help 预先感谢您的任何帮助

Edit: tried it on a different phone and got the same result so presume its a code problem or and android studio project setup error 编辑:在另一部手机上尝试过并获得相同结果,因此假定其为代码问题或Android Studio项目设置错误

May you try this : 可以尝试一下:

FileHandle fileHandle = Gdx.files.internal("levels/1.txt");

String s = new String(fileHandle.readString());

System.out.println(s);

Hope it helps. 希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM