views:

76

answers:

2

I want to have some static numeric and text values as an application resource. For example my data is like this:

Levels 5 First_Level 500 60 1 Second_Level 500 80 1 Third_Level 200 60 1 Fourth_Level 130 30 2 Final_Level 100 30 3
... and another 300 lines...

The format and order of the data is predefined and guaranteed to be valid.

I could read it with java.util.Scanner, but it's extremely slow in Android, reading a 10 KB file takes minutes. It's slow because of the regular-expression-based pattern matching inside (when I traceview'ed it).

What way would you suggest to store them?

+1  A: 

You can store it in a object arraylist, that object just implements Serializable.

Then just ObjectOutputStream.writeObject(list), and later use readObject.

Cytown
just that object serialization is probably the slowest possible approach :-)
Matthias
should not slower than read from res/raw :)
Cytown
+1  A: 

You can store it as raw data in resources/raw (e.g. as CSV or TSV) and use Resources.openRawResource to read from it using an InputStream. That should be reasonably fast.

Matthias
Forgot to mention, this is what I did. The problem is that parsing the numbers are very slow.
yuku
you're saying a 10KB file takes *minutes*? I don't know that Scanner class, but have you tried using a simple BufferedReader and a simple tokenizer or split expression? I can't believe this would take longer than a couple seconds.
Matthias