我没有收到任何异常,但是当我运行时...
InputStream deckFile = context.getAssets().open("cards.txt");
然后,deckFile.read() 返回 -1。该文件位于正确的文件夹中,并且不是空的。
这应该是世界上最简单的事情了......
编辑:AssetManager 确实列出了“cards.txt”,所以这不应该是问题所在。
最佳答案
尝试下面的代码行
InputStream is = getAssets().open("test.txt");
int size = is.available();
byte[] buffer = new byte[size]; //declare the size of the byte array with size of the file
is.read(buffer); //read file
is.close(); //close file
// Store text file data in the string variable
String str_data = new String(buffer);
可用方法返回 Assets 的总大小...
关于java - Android 上 Assets 文件夹中的 InputStream 返回空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14515550/