我没有任何例外,但是当我跑…
InputStream deckFile = context.getAssets().open("cards.txt");@H_404_4@然后,deckFile.read()返回-1.该文件位于正确的文件夹中,并且它不为空. @H_404_4@这应该是世界上最简单的事情…… @H_404_4@编辑: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);@H_404_4@可用方法返回资产的总大小…