简体   繁体   English

Libgdx FileHandle readString()不起作用

[英]Libgdx FileHandle readString() not working

I have created a text file called useraccounts.txt. 我创建了一个名为useraccounts.txt的文本文件。 All i want to do is read the file using the filehandle class but I always get this exception 我要做的就是使用filehandle类读取文件,但是我总是会收到此异常

Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: Cannot open a stream to a directory: useraccounts.txt (Local) 线程“ LWJGL应用程序”中的异常com.badlogic.gdx.utils.GdxRuntimeException:无法打开到目录的流:useraccounts.txt(本地)

Here is my code: 这是我的代码:

FileHande accountsFile = Gdx.files.local("useraccounts.txt");
String text = accountsFile.readString();

An explanation is appreciated! 感谢解释!

are you sure it should be local() actually not internal? 您确定它应该是local()实际上不是内部的吗? - you should notice where do you exactly keep your file. -您应该注意将文件确切保存在哪里。

You can read something more about FileHandle obtaining here: 您可以在这里阅读更多有关FileHandle的信息:

https://github.com/libgdx/libgdx/wiki/File-handling#obtaining-filehandles https://github.com/libgdx/libgdx/wiki/File-handling#obtaining-filehandles

Regards, Michał 问候,Michał

After much frustration, I found out that I had made a folder the same name with the text file by mistake!! 沮丧之后,我发现我误将文件夹与文本文件命名为相同的名称! After deleting the folder all works fine, thank you for replying! 删除文件夹后,一切正常,感谢您的答复!

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

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