我正在使用StringTokenizer来阅读我的游戏地图。问题是我不知道如何获得文件的整个行。例如,这是我的.txt文件
Block 128 0 52 3
Block 192 0
SpeedItem 200 64
Block 256 0
Platform 150 70 500 0 false
Block 320 0 12 75
Block 384 0
这是我如何尝试打印整个行
FileHandle file = Gdx.files.internal("data/" + level + ".txt");
StringTokenizer tokens = new StringTokenizer(file.readString());
while(tokens.hasMoreTokens()){
String type = tokens.nextToken();
System.out.println(type); // with this I only get the first word of the line
if(type.equals("Block")){
list.add(new Brick(Integer.parseInt(tokens.nextToken()), Integer.parseInt(tokens.nextToken())));
}
所以这是我的结果
Block
Block
SpeedItem
Block
Platform
Block
Block
但我还需要打印那些行中的所有数字,例如
Block 128 0 52 3
Block 192 0
SpeedItem 200 64
....
....