我正在使用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
....
....
发布于 2015-03-16 22:01:02
为什么要使用StringTokenizer类?这是遗产课。使用斯普利特(方法。这样你的工作就简单多了。
https://stackoverflow.com/questions/29087686
复制相似问题