Search code examples
filenulllibgdxassets

Libgdx file not reading (null) when run on android device


I'm running my game from android studio with my android phone connected to the PC, and I'm not getting any errors about not finding the file when it should be loaded, which is in my 'android/assets/items/' folder, the file is 'someshop.csv', and its loaded by:

BufferedReader br = new BufferedReader(new
    FileReader(Gdx.files.internal("items/"+place+".csv").file()));

where 'place' = 'someshop'

Works fine on desktop, and I can read lines:

line = br.readline()

However on my phone, my entries (text from file are used to build button text) come up 'null'. I've cleaned and rebuilt the project; no help. Do I need to actually build and deploy (install) the project on to my phone to get this to work?


Solution

  • On Android, the Internal FileType is not backed by an actual File. Rather, it points to an entry in the zip (apk). You should use the FileHandle#reader() method to obtain a Reader which can be used to read the file contents.