• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps 2d image app

Hi everibody! I have to create an app that draws a map reading data from a text file : for example the text file can be like

. index x y orientation
vertex 1 0 0 0
vertex 2 5 0 0.5
vertex 3 10 2 0.3

so i need to do in java something like fscanf does in c (fscanf scans the text file for known formatted data... example, in the file i written i know each line has a string float float float and i need to put them into a specific data structure that can be a list of elements "vertex"

next, when i have all the data, draw a simple image rappresenting the data..

my questions are...
there is a function like fscanf?

and then.. what's better for drawing the 2d map? i have tu use Opengl? At the end i have to draw the image pixel by pixel.. i hope there is something easier then openGL :)
 
You need to use an input stream. There are various options here, but the one I would use is a DataInputStream.
 
You need to use an input stream. There are various options here, but the one I would use is a DataInputStream.

today i was trying to use that but i have got some problems to read string with datainputsream.. how can i do if the file its like

newyork 1 2
rome 5 7

so I know each line begins with a string but i dont know how long it is and i need to put the names in a String value?In c its easy, i simply put something like fscanf(file,"%s %d %d\n",name,x,y); and %s gets the string, no matter how long it is..

Thanks for help!
 
It doesn't matter how long it is. to read the first line of the above text, you would do this:
Code:
DataInputStream dis = new DataInputStream(new FileInputStream(new File(filename)));
String city = dis.readUTF();
int param1 = dis.readInt();
int param2 = dis.readInt();

It will automatically read in the proper number of bytes and convert it to the proper datatype.

EDIT: Actually, I made a mistake. DataInputStream reads and writes binary files. If you want to read a text file, you will want to just use a FileInputStream.
 
Back
Top Bottom