Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading a text file or XML file in Android java

I am currently working on a group project to build an Android game. I have been delegated the task of building a PC based level editor (which is all done).

All I have to do now is decide on the file format for the map that is outputted. At the moment it is just a standard text file with different numbers to represent different tiles; E.G 0=path 1=wall 2=enemy.

1 1 1 1 1 1 1 1
1 0 0 0 2 0 0 1
1 1 1 1 1 1 1 1

The actual Android game then takes this file and stores the values into a 2D Array. However those who are making the actual game are having difficulty opening a text file, and others have told me it has to be done using an XML file. I have now been asked to find a away to take in this input.

Could someone tell me how I would read the text file and put the values into a int array[][] ? Or if it is easier, use an XML file and tell me how to format that file and read the values into a int array[][]

Any help would be appreciated as I didn't learn how to use Android so I find this quite difficult.

Many thanks/

like image 284
Matthew Avatar asked Feb 02 '10 20:02

Matthew


1 Answers

I wouldn't use an xml for that.

I would choose between this two options: Check this first.

Text File

Add the file to /res/raw and read it from there.

Here you have an example code of how to read it.

Serialized structure

You might want to serialize all the int array[][] and save it in /res/raw.

like image 195
Macarse Avatar answered Sep 19 '22 19:09

Macarse