java – Android上的Assets文件夹中的InputStream返回空

前端之家收集整理的这篇文章主要介绍了java – Android上的Assets文件夹中的InputStream返回空前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我没有任何例外,但是当我跑… @H_404_2@InputStream deckFile = context.getAssets().open("cards.txt");

然后,deckFile.read()返回-1.该文件位于正确的文件夹中,并且它不为空.

这应该是世界上最简单的事情……

编辑:AssetManager确实列出了“cards.txt”,因此不应该是问题.

解决方法

尝试下面的代码行 @H_404_2@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);

可用方法返回资产的总大小…

猜你在找的Android相关文章