假设我们有pubspec.yaml喜欢:
public void readMazeFromFile(String fileName) throws IOException, FileNotFoundException, MazeReadException {
Scanner scanFile = new Scanner(new File(fileName));
int lineNum = 0;
while (scanFile.hasNextLine()) {
String line = scanFile.nextLine();
Scanner parsed = new Scanner(line).useDelimiter(",");
Maze maze = new Maze();
if (lineNum == 0) {
if (!parsed.hasNextInt()) {
throw new MazeReadException("Rows and columns not specified", line, lineNum);
}
maze.rows = parsed.nextInt();
maze.cols = parsed.nextInt();
maze.squares = new Square[maze.rows][maze.cols];
}
while (parsed.hasNext()) {
if (parsed.next().equals("Square")) {
int r = parsed.nextInt();
int c = parsed.nextInt();
maze.squares[r][c] = new Square(r, c);
maze.squares[r][c].toObject(parsed);
} else {
if (parsed.next().equals("Explorer")) {
maze.explorer = new Explorer(maze);
maze.explorer.toObject(parsed);
} else if (parsed.next().equals("Treasure")) {
Treasure t = new Treasure(maze);
t.toObject(parsed);
maze.randOccupants.add(t);
//maze.randOccupants.get(maze.randOccupants.indexOf(t)).toObject(parsed);
} else if (parsed.next().equals("Monster")) {
Monster m = new Monster(maze);
m.toObject(parsed);
maze.randOccupants.add(m);
//maze.randOccupants.get(maze.randOccupants.indexOf(m)).toObject(parsed);
}
}
}
parsed.close();
lineNum++;
}
scanFile.close();
}
我可以在运行时的main函数中获得x.y.z版本吗?
答案 0 :(得分:1)
目前没有普遍的方法。有关如何在Grinder包中完成的操作,请参阅https://github.com/google/grinder.dart/blob/19a6d13866de8f4a3b295074a3487eaa77b7a2f8/lib/src/cli.dart#L17。有计划改善这一点。请参阅此讨论https://groups.google.com/a/dartlang.org/forum/m/#!topic/core-dev/8WrVpjD6tt8