I’m trying to read a text file that contains integers and store them into a 2d array.
The problem is splitting.
I can read:
0 0 0
0 1 0
0 0 0
just fine and any numbers 0-9 but I have numbers exceeding 9 (10, 100, 1000).
My method:
int[][] mapArray = new int[11][8];
AndroidFileIO file = new AndroidFileIO(context.getAssets());
InputStream is = null;
try {
is = file.readAsset("maps/map.txt");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Log.d("android", "could not load file");
}
Scanner scanner = new Scanner(is);
scanner.useDelimiter(",");
for (int i = 0; i < 11; i++) {
for (int j = 0; j < 8; j++) {
mapArray[i][j] = scanner.nextInt();
Log.d("android", "" + mapArray[i][j]);
}
}
So I tried using a delimiter and not it hangs and tells me i’m getting a type mismatch?
Any solutions on splitting integers when reading files?
Figured out to use this as my delimiter: