public void writeFile(String filePath, Map input) { Velocity.init(); VelocityContext context = new VelocityContext(); // Weather variable. BucketEntry weather = MapUtil.getBucket(input, "weather").get(0); context.put("wst_insi", MapUtil.getValueOr(weather.getValues(), "wst_insi", "?")); // Soil metadata context.put("classification", MapUtil.getValueOr(weather.getValues(), "classification", "?")); context.put("soil_site", MapUtil.getValueOr(weather.getValues(), "soil_site", "?")); context.put("soil_name", MapUtil.getValueOr(weather.getValues(), "soil_name", "?")); context.put("sl_source", MapUtil.getValueOr(weather.getValues(), "sl_source", "?")); context.put("soil_lat", MapUtil.getValueOr(weather.getValues(), "soil_lat", "?")); context.put("soil_long", MapUtil.getValueOr(weather.getValues(), "soil_long", "?")); // Setup the soil layers. SoilLayer[] layers; BucketEntry soil = MapUtil.getBucket(input, "soil").get(0); ArrayList data = soil.getDataList(); layers = new SoilLayer[data.size()]; double cumThickness = 0.0; for (int i = 0; i < data.size(); i++) { layers[i] = new SoilLayer(); layers[i].ReadFrom((Map) data.get(i)); cumThickness = layers[i].calcThickness(cumThickness); } context.put("layers", layers); // Write template. Template template = Velocity.getTemplate("src\\main\\resources\\AgMIPTemplate.apsim"); FileWriter F; try { F = new FileWriter("Test.apsim"); template.merge(context, F); F.close(); } catch (IOException ex) { Logger.getLogger(ApsimOutput.class.getName()).log(Level.SEVERE, null, ex); } }