Original Post
I have this bit of code I want to port from C++ to Java. The code loads in the position and type of a unit in a strategy game from a text file. The problem is, I'm not familiar enough with the Java file I/O system to do it. With C++ streams it was easy, but here I don't know. Okay, so to explain this, I have a text file containing information about the units in a strategy game. So I would have the data in the file arranged for one unit like this: 1 100 200 This would specify that there is a unit of type one at an x position of 100 and a y position of 200. In C++, I would load the data like so: But I'm not exactly sure how to do this in Java. I'm sorry if this is a simple concept, but I'm very new to Java. Also, I need to load in multiple units from one file, so any info on how to go to the next line would also be appreciated.
std::ifstream in("somedata.txt");
int type;
int x;
int y;
// Unit is a class containing the data for a strategy game unit
Unit someunit;
in >> type >> x >> y;
someunit.setType(type);
someunit.setX(x);
someunit.setY(y);
in.close();